[C++-sig] Re: Returning shared_ptr<boost::python::obj> to Python

David Abrahams dave at boost-consulting.com
Sun Sep 5 00:44:32 CEST 2004


"Jim" <jmastro at rochester.rr.com> writes:

> David Abrahams wrote:
>> boost::shared_ptr<boost::python::object> ?
>>
>> That seems like a terrible idea to me.  boost::python::object already
>> maintains the Python object it holds by reference-counting.
>> shared_ptr adds another layer of reference counting.  I can't imagine
>> a good reason for it.
>
> My reason was to get some kind of ref counting on it, because before I
> started with Boost.Python, the objects that are now Python objects were just
> C++ objects and needed shared_ptr. So I just stupidly changed
> shared_ptr<MyCppObject> to shared_ptr<boost::python::object> without
> thinking about it when I started with Boost.Python. Now I see that it's
> unnecessary to ref count since object already does so, but probably didn't
> when I wrote that. Thanks for straightening me out again.

Sure.  But if you really have MyCPPObject instances (or instances of
something derived from MyCPPObject in Python), it might be a good
idea to stick with shared_ptr<MyCPPObject> instead... just FWIW.

-Dave

-- 
Dave Abrahams
Boost Consulting
http://www.boost-consulting.com




More information about the Cplusplus-sig mailing list