[Python-Dev] Object free lists

Tim Peters tim.one at comcast.net
Tue Jun 15 23:30:57 EDT 2004

[Eric Huss]
> Unfortunately the limit code would be much more complex than in
> frameobject because frameobject does not allocate in blocks.

Ugh -- yup.

> So, we would have to somehow determine if an int block is completely free
> before freeing it.  Some different methods:
> 1) Scan each block and count the number of free integers.  If the block
> contains only free integers, then free it.  This would essentially be the
> code in PyInt_Fini().
> We actually have code that calls PyInt_Fini when we are doing leak
> detection.
> 2) Alternate to #1, it could avoid scanning entire blocks if it detected
> a used int, and instead manually dissect the free_list iff the entire
> block is free instead of rebuilding free_list from scratch like
> PyInt_Fini() does.
> 3) Add a counter of the number of free ints in PyIntBlock.  Free the
> block with this number equals the maximum number of ints in a block.
> The problem with #1 is that it is slow, and one would need to determine
> how often to call it.  #2 has the same problem.
> #3 is a little nicer, at the cost of maintaining the counter (which
> should be negligible).

At which point we're getting close to reinventing pymalloc, except not
enough so:  since the list of int blocks is singly-linked, it's not
efficient to remove an arbitrary one.

I can't make more time tonight, so I look forward to reading the solution in
the morning <wink>.

More information about the Python-Dev mailing list