Am 16.12.2011 um 11:53 schrieb Fabrice Silva: > Le jeudi 15 décembre 2011 à 18:09 +0100, Gregor Thalhammer a écrit : > >> There is an excellent blog entry from Travis Oliphant, that describes >> how to create a ndarray from existing data without copy: >> http://blog.enthought.com/?p=62 >> The created array does not actually own the data, but its base >> attribute points to an object, which frees the memory if the numpy >> array gets deallocated. I guess this is the behavior you want to >> achieve. >> Here is a cython implementation (for a uint8 array) > > Even better: the addendum! > http://blog.enthought.com/python/numpy/simplified-creation-of-numpy-arrays-from-pre-allocated-memory/ > > Within cython: > cimport numpy > numpy.set_array_base(my_ndarray, PyCObject_FromVoidPtr(pointer_to_Cobj, > some_destructor)) > > Seems OK. > Any objections about that ?
This is ok, but CObject is deprecated as of Python 3.1, so it's not portable to Python 3.2. Gregor _______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion