[issue2898] Add memory footprint query

Martin v. Löwis report at bugs.python.org
Mon May 19 22:48:12 CEST 2008


Martin v. Löwis <martin at v.loewis.de> added the comment:

> I'm torn about the extra slot; I'd rather not add one, but I can't see
> how to make this flexible enough without one.

I think adding a default __sizeof__ implementation into object
(__basicsize__ + len()*__itemsize__), plus overriding that in
subclasses, should do the trick.

Not adding the default into object would cause an exception to be
raised whenever sys.sizeof checks for __sizeof__, which is fairly
expensive.

Having to look __sizeof__ up in the class dictionary, and
creating an argument list, is still fairly expensive (given that the
application we have in mind will apply sizeof to all objects,
repeatedly), however, this being a debugging facility, this overhead is
probably ok.

__________________________________
Tracker <report at bugs.python.org>
<http://bugs.python.org/issue2898>
__________________________________


More information about the Python-bugs-list mailing list