[Numpy-discussion] Accessing array members

Konrad Hinsen hinsen at cnrs-orleans.fr
Mon Dec 2 03:42:12 CST 2002


Joachim Saul <list at jsaul.de> writes:

> But what if I create a reference to foo.bar, and later delete foo,
> i.e.
> 
> >>> b = foo.bar
> >>> del foo
> 
> Now the data pointer in b refers to freed data! In the mentioned

And that is why the condition for using PyArray_FromDimsAndData is
that the data space passed is not freed before the end of the process.

> survive the actual 'foo' object. However, I want to program it the
> 'clean' way; any hints on how to do it properly would therefore be
> highly welcome.

I see only one clean solution: implement your own array-like object
that represents foo.bar. This object would keep a reference to foo
and release it when it is itself destroyed.

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