[Numpy-discussion] Array data ownership

Konrad Hinsen hinsen at cnrs-orleans.fr
Tue Nov 19 03:30:04 CST 2002


Marc Poinot <Marc.Poinot at onera.fr> writes:

> That's what I want. Or more exactly, I want "global data that will never be
> freed by Numpy, until I tell it to do so !"

That option does not exist. The options are:

1) NumPy manages the data space of your array. It gets freed when the last
   array object referencing it is destroyed.

2) NumPy assumes that the data space is already allocated and is not
   freed as long as any array object might reference it (which, in
   practice, is until the end of the process).

PyArray_FromDimsAndData is used for allocating arrays that choose the
second option.

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.

> [2] Can I use the PyArrayObject.flags bit "owns the data area" to set it
>     after the PyArray_FromDimsAndData call ? In the case of "yes", which

Whatever this does, it is not documented.

Konrad.
-- 
-------------------------------------------------------------------------------
Konrad Hinsen                            | E-Mail: hinsen at cnrs-orleans.fr
Centre de Biophysique Moleculaire (CNRS) | Tel.: +33-2.38.25.56.24
Rue Charles Sadron                       | Fax:  +33-2.38.63.15.17
45071 Orleans Cedex 2                    | Deutsch/Esperanto/English/
France                                   | Nederlands/Francais
-------------------------------------------------------------------------------




More information about the Numpy-discussion mailing list