Pyhton and C structures in Shared Memory

Alex Martelli aleaxit at yahoo.com
Tue Sep 12 16:56:42 EDT 2000


<philip_john_haynes at my-deja.com> wrote in message
news:8pljd8$np4$1 at nnrp1.deja.com...
> 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.


Alex






More information about the Python-list mailing list