PySizeof: almost useful

Ian Leitch port001 at gentoo.org
Fri Feb 10 19:23:51 EST 2006


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi list,

I'm writing a little module to calculate the size of given objects, I
just need a few little pointers to get the thing into a useful shape.

Code here: http://dev.gentoo.org/~port001/Code/PySizeof/

The points I'm confused about are:

1. My method of determining the malloc() overhead is probably laughable,
what's the correct method?

2. I'm at a loss as how to calculate the size of a long object -- any tips?

3. How much memory do instance, module and instancemethod objects hold?
You'll notice I'm getting the size of most objects internal structures,
what structures' size should I be measuring for such objects?

4. When calculating the size of a dict, if it contains more than the
initial ma_smalltable size (8) should I be subtracting 8 from the len()
number multiplied with the size of a dict entry? See line 73 in pysizeof.py

No doubt there are some other glaring mistakes :)

Many thanks to anyone bored enough to review this code.

- -- Ian
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFD7S6XefZ4eWAXRGIRAre2AJ4nf//qF/O9B+IhVgdQOj+1rLePZwCaAhvH
7FoGfjjhlm4bH4ZoQY+b+SA=
=C3np
-----END PGP SIGNATURE-----



More information about the Python-list mailing list