[Python-Dev] cpython: Issue #3329: Add new APIs to customize memory allocators

Christian Heimes christian at python.org
Sat Jun 15 17:49:41 CEST 2013


Am 15.06.2013 14:57, schrieb Victor Stinner:
> Le 15 juin 2013 03:54, "Victor Stinner" <victor.stinner at gmail.com
> <javascript:_e({}, 'cvml', 'victor.stinner at gmail.com');>> a écrit :
> 
>> Ok, I reverted my commit.
>>
>> I will work on a PEP to explain all these new functions and their use
> cases.
> 
> I created the PEP 445 to reserve the number. It is ready for a review
> but already containssome explanation of the new API.

+1

How about you compare your approach with some other libraries, too?
Other projects have dealt with similar issues in the past, too. libxml2
has an extensive API for memory management and debugging.

I have assembled a list of APIs for you:

OpenSSL has CRYPTO_set_mem_functions() to set memory management
functions globally
http://git.openssl.org/gitweb/?p=openssl.git;a=blob;f=crypto/mem.c;h=f7984fa958eb1edd6c61f6667f3f2b29753be662;hb=HEAD#l124

expat has a per-instance memory handler:
http://hg.python.org/cpython/file/cc27d50bd91a/Modules/expat/xmlparse.c#l717

libtiff has three global hooks _TIFFmalloc(), _TIFFrealloc() and
_TIFFfree() that are used instead of malloc() in its core.
http://trac.imagemagick.org/browser/tiff/trunk/libtiff/tif_unix.c#L258

libxml2 has http://xmlsoft.org/html/libxml-xmlmemory.html

Christian


More information about the Python-Dev mailing list