[SciPy-User] Share memory between python an C++

J. David Lee johnl@cs.wisc....
Fri Oct 26 20:09:00 CDT 2012


Hi Wolfgang,

I'm fairly sure that if you pass a numpy array as an object into a C 
module, you can access the data pointer directly. You should check that 
the C_CONTIGUOUS flag is set for the array and make sure the type is 
correct before you pass the data on, but as far as I know, that's all 
you have to do. You will probably want to look at the PyArray_DATA and 
PyArray_BYTES macros in the numpy API.

David

On 10/26/2012 07:54 PM, FDM wrote:
> Hello list,
>
> I have a couple of functions in the form of shared C++ libraries, and want to use them from within python. Some of them involve big chunks of data which could be represented easily using numpy data types. Therefore, I am searching for a way to call the C++ function, pass a reference or pointer as argument, pointing to memory I have allocated in python, such that I can use the result of the function w/o copying. It should be possible to hide technicalities from a python user. I would apprechiate any hint.
>
> Best, Wolfgang
> _______________________________________________
> SciPy-User mailing list
> SciPy-User@scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user



More information about the SciPy-User mailing list