<br><br><div><span class="gmail_quote">On 5/12/07, <b class="gmail_sendername">Andrew Straw</b> <<a href="mailto:strawman@astraw.com">strawman@astraw.com</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Charles R Harris wrote:<br>><br>>     I'll pitch in a few donuts (and my eternal gratitude) for an<br>>     example of<br>>     shared memory use using numpy arrays that is cross platform, or at<br>>     least
<br>>     works in linux, mac, and windows.<br>><br>><br>> I wonder if you could mmap a file and use it as common memory?<br>Yes, that's the basic idea. Now for the example that works on those<br>platforms...
<br>> Forking in python under linux leads to copies because anything that<br>> accesses an object changes its reference count.<br>I'm not sure what you're trying to say here. If it's shared memory, it's
<br>not copied </blockquote><div><br>Ah, but the child receives a *copy* of the parent memory, right down to the heap and stack. In linux this is implemented as copy-on-write for efficiency, but that won't do much good, for as soon as you touch a python object it's reference count changes and the copy is underway. The one thing you do get is a copy of any open file descriptors and shared memory handles, so you can exchange data that way if you are careful to synchronize your accesses. Pipes are like that. However, when the child exits the files are closed, so some care is needed. Share memory, however, persists.
<br><br>Shared memory sounds like what you want. There are python modules shm and shm_wrapper for unix systems, but windows has that capacity also so the functionality could probably be extended. I've never used the modules, so caveat emptor. I don't quite see how one would handle reference counting to shared memory, so you probably have to explicitly destroy it when you are done. Hmmm, what would be nice is numpy arrays created out of shared memory.
<br><br>Boost seems to have stuff for shared memory, so that might be another starting point. Some info on the python modules is at  <a href="http://nikitathespider.com/python/shm/">http://nikitathespider.com/python/shm/</a>
<br><br>Chuck<br></div><br></div><br>