Hi all! I have a large C++ application and I want to use functions/classes from it in pypy. I use cppyy. My application has own memory managing policy (references counting). That's why I need to *catch* moment when pypy is deleting foreign C++ objects - all of it should be "released" before pypy exits. Can anybody advice a solution in my case? Some using of gc module or some other? Also I tried to change __del__ method of W_CPPInstance in .../pypy/module/cppyy/interp_cppyy.py. Is it right way? Sorry for my bad english, I hope you can understand me :) --- Best regards, Alexander
Hi Alexander,
My application has own memory managing policy (references counting).
are the reference counts applied to the objects directly or through smart pointers? And if the latter, are the smart pointers what you expose through cppyy?
That's why I need to *catch* moment when pypy is deleting foreign C++ objects - all of it should be "released" before pypy exits.
Exposing smart pointers would do that, so would a common base class. Does either one apply?
Can anybody advice a solution in my case? Some using of gc module or some other? Also I tried to change __del__ method of W_CPPInstance in .../pypy/module/cppyy/interp_cppyy.py. Is it right way?
Depends on what you are trying to achieve there. Do you want to call a global function from __del__? What is the life time of the objects? It is also possible, if you just want to call a global function, to not manage the lifetimes on the python side, and explicitly call a cleanup from time to time? (You can manage life times with _python_owns and call __destruct__ explicitly (PyPy2.3) to destroy the C++-side only). Best regards, Wim -- WLavrijsen@lbl.gov -- +1 (510) 486 6411 -- www.lavrijsen.net
participants (2)
-
wlavrijsen@lbl.gov
-
Александр Киранов