Creating a PyObject* from a C double*

Alex Martelli aleax at aleax.it
Sun Apr 13 15:24:32 EDT 2003


Joze wrote:

> Exactly what i was looking for. Thanks a lot !!
> 
> Is there any way to avoid copying the array element by element and
> simply pass a pointer to it?

If you KNOW the array will never, NEVER be freed (typically a
static array), then you can use PyArray_FromDimsAndData, I think.
Personally, I've never actually used it -- copying stuff (typically
one blast of memmove) seems a tiny overhead, and keeping descriptor and
data closer together may give more performance when you're _using_ the
array, for all I know.

But one thing I HAVE done -- instead of keeping the array elsewhere,
just START with the PyArray_FromDims, and use the (double*)parr->data
as "the array itself" right from the start.


Alex





More information about the Python-list mailing list