[Numpy-discussion] Question about __array_struct__

Andrew Straw strawman at astraw.com
Tue Apr 25 10:52:08 EDT 2006


Sasha wrote:

>I cannot deallocate that memory in CObject destructor because it is
>passed to the newly created array which lives long after the interface
>object is deleted.
>
Normally, the array that's viewing the data held by the __array_struct__ 
should keep a reference to the base object alive, thus preventing the 
issue. If the base object isn't a Python object, you'll have to create 
some kind of Python type that will ensure the original data is not 
freed, although this would normally take place via refcounts if the data 
source was a Python object.

> The __array_struct__ mechanism does not seem to
>allow to cause the new array assume ownership of the data, but even if
>it did, I do not know what memory allocator is appropriate.
>
>The only solution that I can think of is to create a dummy buffer type
>with the sole purpose of deleting an array of PyObjects and make an
>instance of that type the "base" of the new array.
>  
>
Yes, that's I do. (See 
http://www.scipy.org/Cookbook/ArrayStruct_and_Pyrex for example.)




More information about the NumPy-Discussion mailing list