Working example of extension class in C/C++ ?
Jack Diederich
jack at performancedrivers.com
Tue Mar 11 12:26:06 EST 2003
On Tue, Mar 11, 2003 at 08:43:48AM -0800, Marc Van Riet wrote:
> I would like to write an extension to access shared memory on Linux.
> I'd like to implement a class with these methods :
look in src/Modules and src/Object in the python distribution for
examples of full-featured C objects defined natively.
<PLUG>probstat.sourceforge.net also has some natively defined simple
classes you could use as examples.</PLUG>
> I've read the Python extension guide and several articles on the web.
> Unfortunately I couldn't find any working example anywhere to get me
> started. The xxobject.c skeleton in the Python source is just for a
> python type, not a class with an __init__ and everything (or am I
> missing something ?)
__init__ isn't really neccessary, since you'll be coding the part that
creates the object, you can do initialization there.
Making a shared memory module for python (for use in mod_python) has
been [low] on my list for awhile. I'll make time to test it if you write it,
though.
Some things to consider.
* A class might not be ideal, because shared memory exists longer than
the scope of the object. So a class abstraction might just confuse
people
* Auto-cleanup of the shared memory is _hard_. What happens if a program
new()s a shared memory segment and then fork()s? You could have the
code check it's PID and change the refcount on the segment at every
access, but this is kinda kludgy
* consider using OSSP MM [http://www.ossp.org/pkg/lib/mm/] a cross-platform
shared memory implementation as the C base for the module. Most other
shred memory interfaces are very *NIX flavor dependent.
-jackdied
More information about the Python-list
mailing list