Memory sizes of python objects?

Erno Kuusela erno-news at erno.iki.fi
Sun Mar 24 17:39:48 EST 2002


In article <3C9E2BA1.E500BE4A at engcorp.com>, Peter Hansen
<peter at engcorp.com> writes:

| I don't get that behaviour.  On my machine, with Python 2.2, for 
| all intents and purposes the memory allocated stays constant.
| Did I overlook something?

hard to say. how did you measure it?

with the following program..

  import os
  
  a = [0] * 1000000
  if 0:
      b = 1
      for i in xrange(len(a)): a[i] = b*51
  else:
      b = 2
      for i in xrange(len(a)): a[i] = b*51
  os.system("ps u %d" % os.getpid())

i get this:

USER       PID %CPU %MEM   VSZ  RSS TTY      STAT START   TIME COMMAND
erno      2664 41.3  3.2 39680 33680 pts/25  S    00:37   0:05 python paa.py

changing the "if 0" to "if 1" gets me

USER       PID %CPU %MEM   VSZ  RSS TTY      STAT START   TIME COMMAND
erno      2691 44.2  0.9 15712 9712 pts/25   S    00:37   0:05 python paa.py

the difference is about 24 megabytes, so i'd say an integer object
takes up 24 bytes on this platform.

  -- erno



More information about the Python-list mailing list