Caching objects in a C extension

Terry Reedy tjreedy at udel.edu
Fri Jan 8 18:48:43 EST 2010


On 1/8/2010 12:50 PM, casevh wrote:

> These are numeric objects created by gmpy. I'm trying to minimize the
> overhead for using mpz with small numbers. Objects are created and
> deleted very often by the interpreter as expressions are evaluated. I
> don't keep ownership of the objects.

CPython creates a hidden list of small ints on startup for the same 
reason. Currently about -10 to 256. int.__new__ checks that a requested 
int object would have a value in this range (if so, reuse) -- or not 
(create new object).




More information about the Python-list mailing list