Shared Memory Modules

Peter Hansen peter at engcorp.com
Tue Nov 25 13:57:50 EST 2003


Thomas Heller wrote:
> 
> Peter Hansen <peter at engcorp.com> writes:
> 
> > Thomas Heller wrote:
> >>
> >> steven.green3 at baesystems.com (S Green) writes:
> >>
> >> > Does any one now if a shared memory module exists, written in python
> >> > for a windows platform. I now one exists for unix?
> >> >
> >> >
> >> > help most appreciated,
> >> >
> >> > S Green
> >>
> >> import mmap
> >
> > The docs suggest that mmap.mmap(x, x, mmap.MAP_SHARED) will work under
> > Unix but not Windows.
> >
> > Does the Windows version really support shared memory, or is the
> > multiple-maps-per-file feature only valid within a single process?
> 
> Yes, it does.  You have to give this memory block a name, though:
> 
> sharedmem = mmap.mmap(0, 16384, "GlobalSharedMemory")
> 
> This allows to access 16384 bytes of memory, shared across processes,
> not backed up by a file in the filesystem.

Thanks, Thomas.

In my opinion the documentation on this is entirely unclear.  I attach
it for reference, but I can't offer any suggestions for improvement (as
I don't know anything about shared memory) except that even after reading
it a second time, Thomas' answer above is very much news to me:

'''tagname, if specified and not None, is a string giving a tag name 
for the mapping. Windows allows you to have many different mappings 
against the same file. If you specify the name of an existing tag, 
that tag is opened, otherwise a new tag of this name is created. If 
this parameter is omitted or None, the mapping is created without a 
name. Avoiding the use of the tag parameter will assist in keeping your 
code portable between Unix and Windows. '''

(from http://www.python.org/doc/current/lib/module-mmap.html)

-Peter




More information about the Python-list mailing list