[Python-Dev] Mixing memory management APIs

M.-A. Lemburg mal@lemburg.com
Wed, 30 Jan 2002 20:15:33 +0100


Neil Schemenauer wrote:
> 
> Michael Hudson wrote:
> > I agree we have too many preprocessor macros, but I don't think we can
> > have free == PyObject_DEL.
> 
> If we don't then many extension modules will break.  The example module
> Modules/xxmodule.c used to allocate using PyObject_New and deallocate
> using free().  I believe there are many modules out there that do the
> same (or use PyMem_Del, etc).

Breaking extensions is not a good idea. After all, these make
Python so much fun to work with (since most of the work is usually
already done ;-).

I do think that we should keep the differentiation between
allocating raw memory buffers and space for Python objects.

Even though this is not currently used, it clarifies the
code somewhat, e.g. to free memory allocated for a Python
object you write PyObject_FREE(), for an raw buffer you
write PyMem_FREE(). 

Who knows... perhaps we might want to
handle Python object memory blocks differently in the
future (e.g. build pymalloc support right into 
PyObject_NEW() and PyObject_DEL()) while leaving user space
memory in the realm of malloc() et al.

-- 
Marc-Andre Lemburg
CEO eGenix.com Software GmbH
______________________________________________________________________
Company & Consulting:                           http://www.egenix.com/
Python Software:                   http://www.egenix.com/files/python/