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

Todd Miller jmiller at stsci.edu
Fri Jan 17 15:17:01 EST 2003

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 

>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 image)
That sounds cool!

>Sebastian Haase
>This SF.NET email is sponsored by: Thawte.com - A 128-bit supercerts will
>allow you to extend the highest allowed 128 bit encryption to all your 
>clients even if they use browsers that are limited to 40 bit encryption. 
>Get a guide here:http://ads.sourceforge.net/cgi-bin/redirect.pl?thaw0030en
>Numpy-discussion mailing list
>Numpy-discussion at lists.sourceforge.net

More information about the NumPy-Discussion mailing list