maximum length of a list & tuple
Bengt Richter
bokr at oz.net
Mon Apr 12 16:43:15 EDT 2004
On Mon, 12 Apr 2004 07:22:26 -0400, Peter Hansen <peter at engcorp.com> wrote:
>Peter Hansen wrote:
>
>> Josiah Carlson wrote:
>>
>>> Checking the memory usage of Python before and after the creation of 1
>>> million integer list, I get a /very/ consistant ~16 bytes per. That
>>> would be 12 bytes for the object, and 4 bytes for each pointer in the
>>> list.
>>
>> Please post the expression you are using, for comparison.
>
>By the way, in case it wasn't clear, we have a disagreement (and perhaps
>a misunderstanding) only about the meaning of the original code posted.
>You believe it is allocating many integers. I believe it allocates
>only a single one. Perhaps one of us is wrong. I hadn't read the code
>in great detail, and still haven't, and perhaps that's my mistake.
>Depending on your reply, I'll actually go back and look at it closely
>and perhaps execute it myself and see the result (in terms of the list
>produced, not in terms of the memory consumption). Maybe you will
>do the same and we'll identify which of us is mistaken...
>
>>> dict([(id(x),x) for x in [1]*100])
{7946208: 1}
>>> dict([(id(x),x) for x in range(5)])
{7939088: 0, 7946208: 1, 7943184: 4, 7945200: 2, 7944192: 3}
>>> dict([(id(x),x) for x in range(5)*10])
{7939088: 0, 7946208: 1, 7943184: 4, 7945200: 2, 7944192: 3}
>>> for v in -6,-5,0,1,99,100:
... print dict([(id(x),x) for x in [v for i in xrange(5)]])
...
{8053508: -6}
{7936720: -5}
{7939088: 0}
{7946208: 1}
{8042496: 99}
{8166456: 100}
>>> for v in -6,-5,0,1,99,100:
... print dict([(id(x),x) for x in [v*1 for i in xrange(5)]])
...
{8166384: -6, 8166444: -6, 8166492: -6, 8166360: -6, 8166468: -6}
{7936720: -5}
{7939088: 0}
{7946208: 1}
{8042496: 99}
{8166360: 100, 8166468: 100, 8166480: 100, 8166348: 100, 8166492: 100}
Regards,
Bengt Richter
More information about the Python-list
mailing list