Shared Memory Modules

Thomas Heller theller at python.net
Tue Nov 25 15:13:44 EST 2003


Irmen de Jong <irmen at -NOSPAM-REMOVETHIS-xs4all.nl> writes:

> Thomas Heller wrote:
>
>>> 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.
>
> That is très cool, it doesn't tell you this in the docs, does it?
> The first argument is 'the file handle' of the file to be mapped,
> and it doesn't say that 0 is valid and means 'no file at all'...
>
> However, I've just tried it, and managed to crash Python in mmap.pyd
> with an application exception... twice. But trying to reproduce it
> now fails-- Python keeps running.
> I did this:
>  >>> import mmap
>  >>> mem=mmap.mmap(0,3000000,'irmen')
>  >>> mem[0]='a'
>  >>> mem[2000000]='a'
> and initially, it crashed......... Python 2.3.2 on win xp)

This works for me even from the beginning (with 2.3 CVS version, XP Pro).

Understading which parameters to pass apparently requires 

- reading the mmapmodule.c sources
- and reading about CreateFileMapping and MapViewOfFile in MSDN.

It would be great if someine could submit a patch for the docs <wink>.

I vaguely remember, but am not able to find it anymore: didn't AMK once
had an article about this somewhere?

Thomas




More information about the Python-list mailing list