memory leak with large list??

John Machin sjmachin at lexicon.net
Sun Jan 26 02:39:27 EST 2003


bokr at oz.net (Bengt Richter) wrote in message news:<b0va52$hac$0 at 216.39.172.122>...
> On Sat, 25 Jan 2003 07:41:42 -0500, Tim Peters <tim.one at comcast.net> wrote:
> 
> >[someone]
> >>> Then I generate a large list (12 million floats), either using map,
> >>> a list comprehension, or preallocating a list, then filling it using a
> >>> for loop.
> >
> >[Terry Reedy]
> >> 12 million different floats use 12 million * sizeof float object
> >> bytes. Float object is at least 8 bytes for float + object overhead
> >> (about 4 bytes?)
> >
> >Each object has at least a pointer to the object's type object, and a
> >refcount, for at least 8 bytes of overhead.  So a float object consumes at
> >least 16 bytes.
> Why do you need to duplicate the type pointer for all those? I.e., if
> you allocated space in decent-size arrays of object representations without
> type pointer, and just reserved a header slot in front of the array, [snip]

You'll have to pardon me if my brain appears fried (possible; 40
degrees (Celsius) here yesterday) but I don't understand Bengt's
question, nor Tim's answer.

Shouldn't the answer be: (a) You can't do that with the Python "list"
container, which can contain objects of *any* type (b) You can do that
with a different container, if you restrict all the objects in the
container to being of the one type (c) That has been done, for many
types; see the "array" module.




More information about the Python-list mailing list