[Numpy-discussion] make C array accessible to python without copy

Sebastian Haase haase at msg.ucsf.edu
Fri Feb 21 23:10:05 CST 2003

Short follow up: 
1) Is it planned to support this more directly?
2) How much does it cost to create a buffer object if it 
uses my already allocated memory ?
3) Can I change the pointer so that it points to a 
different memory space WITHOUT having to recreate any 
python objects? Or would that "confuse" the buffer or 
numarray?    (We are hoping to aquire 30 images per second 
- the images should get written into a circular buffer so 
that the data can be written to disk in larger chunks - 
but the python array should always refer to the current 
image )

Thanks for all the nice toys (tools) ;-)
Sebastian Haase

On Fri, 17 Jan 2003 18:16:01 -0500
  Todd Miller <jmiller at stsci.edu> wrote:
>Sebastian Haase wrote:
>>What is the C API to make an array that got allocated,
>>let's say, by  a = new short[512*512],
>>accessible to python as numarray.
>What you want to do is not currently supported well in C. 
> The way to do what you want is:
>1.  Create a buffer object from your C++ array.  The 
>buffer object can be built such that it refers to the 
>original copy of the data.
>2.  Call  back into Python (numarray.NumArray) with your 
>buffer object as the buffer parameter.
>You can scavenge the code in NA_newAll (Src/newarray.ch) 
>for most of the callback.
>>I tried NA_New - but that seems to make a copy.
>>I would need it to use the original memory space
>>so that I can "observe" the array from Python WHILE
>>the underlying C array changes (it's actually a camera 
>That sounds cool!
>>Sebastian Haase

More information about the Numpy-discussion mailing list