[C++-sig] Transfer of ownership
Eric Jardim
ericjardim at gmail.com
Wed Aug 10 21:26:20 CEST 2005
Hi, all...
This is a simple question. I was reading the docs where it says about the
"transfer of ownership" of a C++ object pointer. I am dealing exacly this
situation, where the "with_custodian_and_ward" policy is not enough to
prevent Python objects to delete C++ couterparts. The only hack is to hold
references, but it is not a complete solution.
So, I read the FAQ entry where it explain how to deal with this issue:
http://www.boost.org/libs/python/doc/v2/faq.html#ownership
But there, it speaks about using an "std::auto_ptr". On the other side, I am
using "boost::shared_ptr" to hold my objects. I really do not know the
difference between them, but I imagine they provide similar funcionality.
So I will split my question in 3 parts:
- Is it possible to take the ownership with "boost::shared_ptr", or do I
have to change my held types to "std::auto_ptr"?
- Is there any difference in practice, using boost's or std's smart
pointers? I just use them for holding Boost.Python extensions.
- As those functions with smart pointers do not exists, I suppose that I
will have to write wrappers like:
void b_insert(B& b, std::auto_ptr<A> a)
{
b.insert(a.get());
a.release();
}
Is there any special reason for this to be a non-const reference to "b"?
Could it be a const reference or a const/non-const pointer to "b"? Is there
any implications?
Thanks,
[Eric Jardim]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20050810/bf28d0d4/attachment.htm>
More information about the Cplusplus-sig
mailing list