[Numpy-discussion] Wrapping C array

Carlos Pita carlosjosepita at yahoo.com.ar
Wed May 18 08:43:34 EDT 2005


But as NA_NewArray does, FromDimsAndData copies
its contents from the passed pointer, which
is what I'm willing to avoid.

PyObject* PyArray FromDimsAndData(int nd, int *dims, int type, char *data)

   This function will allocate a numarray of the specified
   shape and type, and it's contents will be copied from the
   specified data pointer.

The fact is that the audio buffer to be wrapped
is a simple, fixed-size and contiguous C
array, so I guess it should be easy to access
through a numarray. But NA_NewArray and friends
all seems to copy contents to a buffer of their
own.

Thank you.
Regards,
Carlos

> On Tue, May 17, 2005 at 09:36:22PM -0300, Carlos Pita wrote:
> > Hi!
> > I need to wrap a pre-existent C array into
> > a numarray. It shouldn't be a copy of the
> > original array because this is an audio buffer
> > with a fixed address and also input/output
> > copying from/to the buffer would be overkilling,
> > so the numarray *must* be lightly wrapping the
> > buffer and not a memcpy of it. But NA_NewArray
> > duplicates the passed buffer so I'm not sure
> > how to achieve the goal stated above or if
> > it's possible at all.
> > Can you help me?
> 
> I'm not sure for Numarray, but for Numeric, you can use
> PyArray_FromDimsAndData(). There should be a similar function in
> numarray.  
> 






More information about the NumPy-Discussion mailing list