Pyhton and C structures in Shared Memory

Alex Martelli aleaxit at
Tue Sep 12 22:56:42 CEST 2000

<philip_john_haynes at> wrote in message
news:8pljd8$np4$1 at
> Hello All,
> This is a post from a recent convert to Python.
> I have big blob of shared memory, essentially
> arrays of C structures.
> I am looking to C extensions as the methodolgy
> for accessing these structures from within
> Python.  Is it the right direction (what about
> SWIG)?
> Does Python have a module that implements the
> shm* functions?

mmap (in Python 2.0 and up, only, I think) should
be exactly what you want.  It's now a part of the
standard library.  mmap lets you get at the shared
memory data, then you can use the existing struct
or array modules to pack/unpack it to/from Python
usable tuples &c... (disclaimer: this works in Win32,
as memory-mapped files and shared-memory are
one and the same thing there; this should be checked
out under your Unix version, of course).

If mmap isn't right for you, then a C extension (built
more easily with SWIG's help, to be sure) may indeed
be best.


More information about the Python-list mailing list