[C++-sig] Ownership question.
tALSit de CoD
talsit at talsit.org
Sun Apr 27 07:04:23 CEST 2003
I have a class method that takes ownership of the object passed into it,
and I want to know, how do I let boost.python know about this and not to
manage that object anymore?
Should i do a kludge job like make a function that return a new object, but
telling boost.python not to manage it, then, when I add it into the method,
it's "disappeared" from boost.python?
Original thing:
class cAnimCurveKey { /* stuff */ }
class cAnimCurve {
void addKey (cAnimCurveKey * key); // takes ownership of the
key
}
When i wrap that in boost.python, and i create a key and then add it to the
animation curve:
>>> aninCurve = cAnimCurve ()
>>> key = cAninCurveKey ()
>>> animCurve.addKey (key)
What happens there?? Is python the owner of the object key? I was thinking
of this hack:
(In C++ / boost.python)
cAnimCurveKey * newAnimCurveKey () { return new cAnimCurveKey (); }
BOOST_PYTHON_MODULE (kikura) {
def ("newAnimCurveKey", newAnimCurveKey, return_value_policy
<reference_existing_object> ());
}
And that way, python is not in charge of that object, and in theory, every
key that gets created, is created to be put in an AnimCurve, so it's not
_that_ bad, is it?
OOOOORRRRRR Is there a way to specify to boost.python that you don't want
it to manage or track that object anymore?
Thanks folks
Cheers!
tALSit de CoD | talsit.org
More information about the Cplusplus-sig
mailing list