[SciPy-User] [SciPy-user] numpy and C

tinauser tinauser@libero...
Fri Jun 11 06:50:33 CDT 2010

Charles R Harris wrote:
> I don't know the details of your larger design, so perhaps my concerns are
> irrelevant. The virtue of PyArray_SimpleNewFromData is that the array can
> be
> deallocated without affecting the buffer memory.
> PyArray SimpleNewFromData (PyObject*) (int nd, npy intp* dims,int typenum,
> void* data)
> Sometimes, you want to wrap memory allocated elsewhere into an ndarray
> object
> for downstream use. This routine makes it straightforward to do that. The
> first three arguments are the same as in PyArray SimpleNew, the final
> argument is a pointer to a block of contiguous memory that the ndarray
> should use as it’s data-buffer which will be interpreted in C-style
> contiguous
> fashion. A new reference to an ndarray is returned, but the ndarray will
> not
> own its data. When this ndarray is deallocated, the pointer will not be
> freed.
> You should ensure that the provided memory is not freed while the returned
> array is in existence. The easiest way to handle this is if data comes
> from
> another reference-counted Python object. The reference count on this
> object
> should be increased after the pointer is passed in, and the base member of
> the returned ndarray should point to the Python object that owns the data.
> Then, when the ndarray is deallocated, the base-member will be DECREF’d
> appropriately. If you want the memory to be freed as soon as the ndarray
> is
> deallocated then simply set the OWNDATA flag on the returned ndarray.
> Chuck
Dear Charles, 
the point is that I'm using the PyArray just as an "holder" of a pointer
(the char* data).I allocate this only at the beginning and change the its
value all the time.
If I understood it correctly, using  SimpleNewFromData I'm just setting the
value of "data", that I have anyway to change everytime I'm getting a new
The point is that I want to avoid to allocate at run time.


View this message in context: http://old.nabble.com/numpy-and-C-tp28767579p28854160.html
Sent from the Scipy-User mailing list archive at Nabble.com.

More information about the SciPy-User mailing list