Daniel Drake wrote:
>Hi,
>
>I have an area of memory which is shared between processes (it is
>actually a shared memory segment). The address of this memory is stored
>in a python long variable, which I pass to various custom C/C++ python
>modules.
>
>I would like to construct a numpy array in this area. Is there any way I
>can tell numpy to use a specific address (stored as a long) to use as
>storage for the array?
>
This functionality is already available. There are two ways to do it.
1) Create an object with an __array_interface__ attribute that returns a
dictionary with shape, typestr, and data fields. The data field should
return the tuple (memory-address-as-long,
True-if-read-only-otherwise-False).
Passing this object into the asarray constructor will use the memory given
2) Use the asbuffer function in numpy.core.multiarray (it's not exposed
to numpy yet) to create a buffer object from the memory address and then
use frombuffer to create an array from the memory.
Good luck,
-Travis
|