memory usage, temporary and otherwise
mk
mrkafk at gmail.com
Wed Mar 3 13:47:14 EST 2010
Obviously, don't try this on low-memory machine:
>>> a={}
>>> for i in range(10000000):
... a[i]='spam'*10
...
>>> import sys
>>> sys.getsizeof(a)
201326728
>>> id(a[1])
3085643936L
>>> id(a[100])
3085713568L
>>> ids={}
>>> for i in range(len(a)):
... ids[id(a[i])]=True
...
>>> len(ids.keys())
10000000
Hm, apparently Python didn't spot that 'spam'*10 in a's values is really
the same string, right?
So sys.getsizeof returns some 200MB for this dictionary. But according
to top RSS of the python process is 300MB. ps auxw says the same thing
(more or less).
Why the 50% overhead? (and I would swear that a couple of times RSS
according to top grew to 800MB).
Regards,
mk
More information about the Python-list
mailing list