-
Notifications
You must be signed in to change notification settings - Fork 73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ndarray data ownership question #28
Comments
What you want to do here is create an opaque Python object that does nothing but hold your https://github.com/ndarray/ndarray/blob/master/include/ndarray/bp/Array.h#L33 It uses an |
OK, so essentially, the destroyManager function will get called when the objected is del'ed in python (or I guess when the GC decides to call it). If I look closely, it seems like I will have to have different destroyManager functions depending on the type. I will probably use templates here. I wish I had looked at your ndarray/Vector class earlier. It would've helped out. I still think that the use case I mentioned might be good to add in the library (converting a |
Yeah, I agree that it'd be worthwhile to add this functionality to Boost.NumPy. I'll keep this issue open to remind me to do that. |
My typical use case is: and then the variable arr is returned to python and will be deleted in python, and I am experiencing a memory leak for the data_. How could I avoid the memory leak? @TallJimbo Thanks so much. |
Never mind, I solved the problem. For anyone who are experiencing the same memory-leaking, here is my solution. Hope it helps. |
It sure does help! This is an application of what 7starsea said to do boostorg/python#97 (comment) |
Hi,
Lets say I have a
boost::shared_ptrstd::vector vp;
What is the best way to construct a numpy array and return it?
I am currently using:
std::vector &vec(*vp);
np::from_data(vec.data(), np::dtype::get_builtin() , p::make_tuple(vec.size()), p::make_tuple(sizeof(int)), owner);
The question is: what should I put for owner? I'd like to be able to call vp.reset() in my C++ code [and therefore giving up ownership] and have python manage the memory as long as it needs to (and clean up if the python object is ever del'ed).
I am assuming having a p::object() on the stack, but I am guessing that it is probably not a good thing (as it will destruct when my function ends). So, I can create a "dummy" owner and have it linger around in my c++ code, but that'll keep objects around longer than they are needed (essentially leaking memory, w/o technically doing so).
Thanks in advance.
The text was updated successfully, but these errors were encountered: