API/C memory mananegemnt problem

Aahz aahz at pythoncraft.com
Sat Mar 11 14:24:18 EST 2006


In article <1hc18a8.1u0a6cx14wyhuhN%aleaxit at yahoo.com>,
Alex Martelli <aleaxit at yahoo.com> wrote:
><plahey at alumni.caltech.edu> wrote:
>> 
>> I think I understand the original statement now.  What you are really
>> saying is that there is a pool of Python float objects (which can, at
>> different times, wrap different values) which can grow but never
>> decrease in size.  So the memory held by this pool is dictated by the
>> maximum number of floats that have ever been simultaneously active
>> (accessible).
>> 
>> The same goes for integers.  All the more reason to avoid range(.) and
>> use xrange(.).
>
>Uh? The integers produced as you loop over xrange will be just immortal
>as those that get into the list built by range, so why is int
>immortality any reason to use one over the other?

Because unless you save the ints produced by xrange(), you're reusing
slots in the free list as you go through the loop, whereas range() chews
up a gob of memory that will never get released even if you never
otherwise use all the ints it produces.
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

"19. A language that doesn't affect the way you think about programming,
is not worth knowing."  --Alan Perlis



More information about the Python-list mailing list