Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Mmm I don't quite get why sys.getsizeof is reporting a bigger size in the slotted class, it should be the other way around according to that post.

Test code at: http://codepad.org/wlb53BLf not sure if I'm missing something...



Per the Python 3 docs (for some reason not in the Python 2 docs, but the same holds): "Only the memory consumption directly attributed to the object is accounted for, not the memory consumption of objects it refers to."

Most of the space for the NonSlotted version is in the __dict__, and if you print the size of ni.__dict__ you'll probably get a couple of hundred bytes.

There are better, recursive ways to get the real size of a Python object in memory, for example see: http://pythonhosted.org/Pympler/asizeof.html#asizeof


Nice, just used pympler.asizeof and it reported that the slotted version has about 22% of the size of the non-slotted version.


I tried with this:

http://pastebin.com/nfqtDUiW

Try comment and un-comment the __slot__. You can measure the program memory footprint using

pmap -x <PID>

where <PID> is obtained using

pgrep python

...more than one python process?

cat /proc/<PID>/cmdline | xargs -0 echo




Consider applying for YC's Winter 2027 batch! Applications are open till November 2.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: