embedded Python - optimization for creating/destroying many small objects

Skip Montanaro skip at pobox.com
Mon Jun 24 18:39:13 EDT 2002

    Paul> I would like to simply create ONE of these objects and reuse it
    Paul> for the entire loop, so I am not paying for the memory
    Paul> allocation/deallocation overhead.

Define your object to have something akin to a __setstate__ method, create a
single instance of it before the loop, then set its state during each pass
of the loop:

    holder = MyContainer()
    while 1:

Skip Montanaro
skip at pobox.com
consulting: http://manatee.mojam.com/~skip/resume.html

More information about the Python-list mailing list