Assign ownership of Python-constructed object to C++ runtime

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Assign ownership of Python-constructed object to C++ runtime

Adam Preble
I am pondering trying to eliminate some usages of shared pointers in my code since I have finally completed enough of it that I have good ownership rules for things in place.  I still have one spot, which is basically the main door to the C++ runtime, where I have a problem.  I've been creating instances of some objects in Python, with the purpose of assigning to another object for safekeeping.  Really that other object is what I have in mind for managing everything about these objects--including their runtimes.  But I see the objects get destroyed when the Python declaration for them go out of scope.  That would normally be the right thing.  I'm trying to think of alternatives.  The best I can think of is to use a static factory method instead that returns an internal reference.  I'm intend to experiment with that now but I am wondering if there are some other things to consider instead.

Inevitably somebody will ask why I'm doing away with the shared pointers.  I have some cycles due to communication that means a lot of stuff never actually gets deleted due to the reference-counting methodology in them.  When I used weak references, I found they were getting deleted too eagerly.  And by this point, I otherwise have gotten an ownership hierarchy down.

_______________________________________________
Cplusplus-sig mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/cplusplus-sig
Loading...