[C++-sig] create boost array from a Numpy PyArray without copying data? (original) (raw)
Ravi lists_ravi at lavabit.com
Wed Jan 21 15:33:32 CET 2009
- Previous message: [C++-sig] create boost array from a Numpy PyArray without copying data?
- Next message: [C++-sig] create boost array from a Numpy PyArray without copying data?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Wednesday 21 January 2009 03:40:00 Sebastian Walter wrote:
Apparently I have to increase the refcount manually when I return a raw PyObject. So I wrote getter functions like that:
PyObject* getrhs(){ return incref((PyObject *) arraymyrhs); } I'm not sure that this is the way it should be done. But it solved the memory corruption problem.
In this case, you are essentially creating a memory leak. The returned array will never be deleted by python since its reference count will never go to zero. Please see http://blog.enthought.com/?p=62 for information on fixing this issue. The code I pointed out earlier encapsulates this using a custom deleter in C++ which can be used independently of ublas.
Regards, Ravi
- Previous message: [C++-sig] create boost array from a Numpy PyArray without copying data?
- Next message: [C++-sig] create boost array from a Numpy PyArray without copying data?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]