Python's biggest compromises

Paul Rubin http
Fri Aug 1 17:38:37 EDT 2003


Brian Quinlan <brian at sweetapp.com> writes:
> I'm not sure that I believe this. In Python, everything is an object
> that participates in GC including integers and other light-weight types.
> Imagine that you have a mathematic expression that creates a dozen
> floats objects as part of its evaluation. Do you believe that it is
> faster to add those dozen floats to a list for later collection than to
> decrement an integer, notice that the decremented value is 0 and
> immediately reclaim the memory? That would not be my intuition (but my
> intuition is often wrong :-)).

In a fast GC system you would just allocate the floats from a
contiguous block.  Later you would copy the reachable floats from that
block to another block.  If no floats are reachable, you don't copy
anything.  There are all kinds of optimizations you can use, including
making clever use of memory protection hardware to notice when your
allocator has run over the end of a block so you don't have to even
make an explicit pointer comparison, that can make all this run very fast.

Andrew Appel has a book about garbage collection where he discusses
these methods in detail.




More information about the Python-list mailing list