mmap and shared memory

Carl Banks pavlovevidence at gmail.com
Mon Feb 11 20:04:27 EST 2008


On Feb 11, 6:41 pm, Matias Surdi <matiassu... at gmail.com> wrote:
> Suppose I've a process P1, which generates itself a lot of data , for
> example 2Mb.
> Then, I've a process P2 which must access P1 shared memory and,
> probably, modify this data.
> To accomplish this, I've been digging around python's mmap module, but I
> can't figure how to use it without files.
>
> Could anybody explain me how could this be accomplished? An example will
> be very appreciated. Thanks a lot for your help.

In C you can use the mmap call to request a specific physical location
in memory (whence I presume two different processes can mmap anonymous
memory block in the same location), but Python doesn't expose this.

There isn't really as much drawback to using a file as you might
expect, and there are benefits.  If you use an anonymous map the OS
could still write that memory to swap space, which, if your swap space
is fixed and limited, might negatively affect performance for the rest
of the system.


Carl Banks



More information about the Python-list mailing list