![](https://secure.gravatar.com/avatar/947028b0d6f0eb1344f5be4e2f686c27.jpg?s=120&d=mm&r=g)
I'm currently tinkering with the following problem and what like to hear your suggestions: Within a C module I define a new Python type 'IM' (representing an image). The indexing or slicing facilities of NumPy arrays were tailormade for the manipulation of the internal data of its instances. Thus, I could provide a method 'asarray', which creates a properly typed array object 'a' referring to the data of an IM instance 'im': a = im.asarray() I could use PyArray_FromDimsAndData() to create the array instance. Unfortunately, this wouldn't work, since 'a' would not get notified about the death of 'im'. However, if I could prevent 'im' from being garbage collected before all array instances referring to its data are deleted, it should work. NumPy's array type uses a mechanism to prevent garbage collection of array instances if there are other instances that share data with it. My idea was, to use this mechanism, that is to let the asarray method increment im's reference count and let a->base refer to im. Do you think this is a reliable approach? Thanks, Ralf -- -------------------------------------------------------------------------- Ralf Jüngling Institut für Informatik - Lehrstuhl für Mustererkennung & Bildverarbeitung Georges-Köhler-Allee Gebäude 52 Tel: +49-(0)761-203-8215 79110 Freiburg Fax: +49-(0)761-203-8262 --------------------------------------------------------------------------
participants (1)
-
Ralf Juengling