When to use PyMem_Malloc()?

Jon Perez jbperez808 at yahoo.com
Thu Apr 8 00:31:34 EDT 2004


According to the Python docs...

"In most situations ... it is recommended to allocate memory from
the Python heap specifically because the latter is under control
of the Python memory manager. For example, this is required when the
interpreter is extended with new object types written in C. Another
reason for using the Python heap is the desire to inform the Python
memory manager about the memory needs of the extension module. Even
when the requested memory is used exclusively for internal,
highly-specific purposes, delegating all memory requests to the
Python memory manager causes the interpreter to have a more accurate
image of its memory footprint as a whole. Consequently, under certain
circumstances, the Python memory manager may or may not trigger
appropriate actions, like garbage collection, memory compaction or
other preventive procedures. Note that by using the C library
allocator as shown in the previous example, the allocated memory for
the I/O buffer escapes completely the Python memory manager."


Are there any disadvantages to using PyMem_Malloc() such that
there are times when one would prefer to use a plain malloc()?



More information about the Python-list mailing list