Re: [Numpy-discussion] views and object lifetime
Matthieu Brucher matthieu.brucher at gmail.com writes: B has a reference to A. Could you be more specific? Where is this reference stored? What C api functions are used? Matthieu 2009/2/18 Neal Becker ndbecker2 at gmail.com: How is it ensured, at the C api level, that when I have an array A, and a view of it B, that the data is not destroyed until both A and B are? ___ Numpy-discussion mailing list Numpy-discussion at scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] views and object lifetime
2009/2/18 Neal Becker ndbeck...@gmail.com: Matthieu Brucher matthieu.brucher at gmail.com writes: B has a reference to A. Could you be more specific? Where is this reference stored? What C api functions are used? I don't remember, and I don't have the Numpy book here. But if B is a view on A, a flag indicates that B does not own the data, and another field is a pointer to A. Matthieu -- Information System Engineer, Ph.D. Website: http://matthieu-brucher.developpez.com/ Blogs: http://matt.eifelle.com and http://blog.developpez.com/?blog=92 LinkedIn: http://www.linkedin.com/in/matthieubrucher ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] views and object lifetime
On Wed, Feb 18, 2009 at 01:02:54PM +, Neal Becker wrote: B has a reference to A. Could you be more specific? Where is this reference stored? In [1]: import numpy as np In [2]: a = np.empty(10) In [3]: b = a[::2] In [4]: b.base is a Out[4]: True Gaƫl ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] views and object lifetime
2009/2/18 Neal Becker ndbeck...@gmail.com: Matthieu Brucher matthieu.brucher at gmail.com writes: B has a reference to A. Could you be more specific? Where is this reference stored? What C api functions are used? I'm probably not qualified to be much more specific, these links should provide the necessary detail: http://docs.scipy.org/doc/numpy/reference/c-api.html#numpy-c-api http://docs.python.org/c-api/intro.html#objects-types-and-reference-counts http://docs.python.org/extending/newtypes.html The Python interpreter takes care of when to free the memory associated with an object once it's reference count reaches zero. The object reference counts are increased and decreased directly in C code using the Py_INCREF and Py_DECREF macros whenever a new object is created or a new pointer assigned to an existing object. Cheers, Scott ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] views and object lifetime
Neal Becker wrote: How is it ensured, at the C api level, that when I have an array A, and a view of it B, that the data is not destroyed until both A and B are? One array, A, owns the data and will deallocate it only when its reference-count goes to 0.The view, B, has a reference to A (stored in the base attribute) and has OWNDATA set to false so that its deallocator simply decreases the reference count on the array, A, that actually owns the data. In the code look at the `array_dealloc` function in arrayobject.c and the base and OWNDATA flag-bit in the array-structure for details. -Travis ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion