Passing a memory address (pointer) to an extension?

John Nagle nagle at animats.com
Thu Oct 23 00:03:08 EDT 2008


Philip Semanchuk wrote:
> I'm writing a Python extension in C that wraps a function which takes a 
> void * as a parameter. (The function is shmat() which attaches a chunk 
> of shared memory to the process at the address supplied by the caller.) 
> I would like to expose this function to Python, but I don't know how to 
> define the interface.

     Use message passing, not shared memory.  CPython is so slow that you'll
never notice any performance gain from using shared memory.

     Also, if you're asking this question, you probably don't know enough
to keep out of trouble in this area.  You need to thoroughly understand
concurrency, locking, shared memory locking, the Python Global Interpreter
Lock, Python memory management, and the implications of the interactions
between all of them. Otherwise you'll get race conditions, crashes within
the Python system, lockups, and/or terrible performance.

     And none of the usual debugging tools for Python will help you.

				John Nagle



More information about the Python-list mailing list