[Numpy-discussion] Array data ownership

Marc Poinot Marc.Poinot at onera.fr
Tue Nov 19 04:25:02 CST 2002


Konrad Hinsen wrote:
> 
> If I understand you correctly, you want NumPy to create an array
> object and allocate the data space, but make sure that the data space
> is not freed before you "allow" it. In that case, just create an
> ordinary array and keep an additional reference to it. When the data
> space may be destroyed, you remove the reference. However, there is no
> guarantee that the data space will be freed immediately, as there
> might still be other references around.
> 
No. I want to set the memory zone of the array but once this zone is set, I want
numpy to manage it as if it was owner of the memory.

I have an external lib which allocates the returned memory zone. I put this
memory zone into a PyArrayObject using PyArray_FromDimsAndData in order
to avoid memory copy. But I want now this array to be the owner of the
allocated zone. I mean I want this zone to be released if the Python object
is deleted. The ref count of Python is ok for me, as long as an array is
sharing the data, python won't release it. But I want Python to delete
the memory zone if the last reference is removed.

Marcvs [alias I'll have a try with myarray->flags |= OWN_DATA;
        and I'll let you know about my experiments...]




More information about the Numpy-discussion mailing list