[Python-Dev] Moving forward on the object memory API (original) (raw)

Neil Schemenauer nas@python.ca
Mon, 1 Apr 2002 06:54:57 -0800


Guido van Rossum wrote:

> Next, we base PyObject{MALLOC,REALLOC,FREE} on pymalloc. Basically: > > #ifdef WITHPYMALLOC > #define PyObjectMALLOC(n) PyMallocMalloc(n) > #define PyObjectREALLOC(op, n) PyMallocRealloc((void *)(op), (n)) > #define PyObjectFREE(op) PyMallocFree((void *)(op)) > #else > #define PyObjectMALLOC(n) PyMemMALLOC(n) > #define PyObjectREALLOC(op, n) PyMemREALLOC((void *)(op), (n)) > #define PyObjectFREE(op) PyMemFREE((void *)(op)) > #endif

Couldn't these always use the first set of definitions? I suppose that when configured --without-pymalloc, PyMallocMalloc and friends are aliases for malloc?

No, the PyMalloc* functions are only available if pymalloc is enabled. We could make it so that the PyMalloc* functions are always available. People who don't use pymalloc would take a performance hit though.

Also, do we need these at all? (Hm, I must be missing something, but I can't figure what.)

Do you mean PyObject_{MALLOC,REALLOC,FREE}? I think we do. There needs to be a way to allocate memory using the object allocator. I like PyObject_MALLOC better than PyMalloc_MALLOC and it was also present in previous releases.

> PyMemDEL and PyMemFree need to call pymalloc: > > #define PyMemDEL(op) PyObjectFREE(op)

Why not PyMallocMalloc?

See above (pymalloc may be disabled).

> We go through the source and replace all the PyMem* function calls with > the equivalent PyMem* macro calls and replace PyMemDEL with > PyMemFREE.

Or PyObjectDel (depending on the situation)?

Nope. There should be no place in the CVS source that calls PyMem_DEL when it should be PyObject_Del.

Is there a difference between PyMemMALLOC and PyMemNEW? Between PyMemREALLOC and PyMemRESIZE? If there isn't, shouldn't we recommend one set and deprecate the other? I think I like the NEW family best (it's got seniority).

NEW and RESIZE are type based while MALLOC and REALLOC work by bytes. I think you need them both.

I suppose the patches that changed PyObjectNew into PyMallocNew can be reverted now?

Yes.

Neil