Creating Python objects out of a memory pool

Steven D. Majewski sdm7g at virginia.edu
Wed Dec 6 14:05:18 EST 2000


On Wed, 6 Dec 2000, Damjan wrote:

> Is it posible to create Python objects in a known space in the memory
> (like in a shared memory).
> I want some some objects created in python to be in the shared memory
> pool, while others to be allocated as usual. Is there a way to hook in to
> the Python memory allocation from Python itself or I'll haveto use the C
> API?
> 

You need to write a custom allocator in C and recompile Python. 
Look at Include/pymem.h : 

/*
 * Core memory allocator
 * =====================
 */

/* To make sure the interpreter is user-malloc friendly, all memory
   APIs are implemented on top of this one.

   The PyCore_* macros can be defined to make the interpreter use a
   custom allocator. Note that they are for internal use only. Both
   the core and extension modules should use the PyMem_* API.

   See the comment block at the end of this file for two scenarios
   showing how to use this to use a different allocator. */



-- Steve Majewski <sdm7g at Virginia.EDU>






More information about the Python-list mailing list