I'm working on a python memory profiler where I collect the size of python objects with the following method:
sum(map(sys.getsizeof, gc.get_objects()))
This is significantly the slowest part of the code - especially gc.get_objects
- so I decided to speed it up and rewrite it as a c extension. The problem is that the python c API doesn't give access to the gc modules internal data what is used by gc.get_objects
.
Is it possible to iterate through all objects using the c API, without calling the expensive gc.get_objects
?