[prev in list] [next in list] [prev in thread] [next in thread]
List: python-cpp-sig
Subject: Re: [C++-sig] copy constructors and multiple instances
From: Hans Meine <hans_meine () gmx ! net>
Date: 2011-09-02 8:21:06
Message-ID: 201109021021.06815.hans_meine () gmx ! net
[Download RAW message or body]
Am Donnerstag, 1. September 2011, 22:52:56 schrieb Jim Bosch:
> Yup. With boost::shared_ptr, you don't even need to include it as a
> template argument of class_, if you instead add the line:
>
> boost::python::register_ptr_to_python< boost::shared_ptr<Scene> >();
>
> This allows you to return shared_ptr to Python, but because a
> boost::shared_ptr can use an arbitrary deleter, Boost.Python can convert
> any wrapped Scene object (even one that doesn't hold a
> shared_ptr<Scene>) into a shared_ptr<Scene> with correct reference
> counting.
>
> If you do include boost::shared_ptr<Scene> in the class_ template
> arguments, all Scene objects constructed in Python will be inside a
> shared_ptr, but because of the above, that isn't necessary unless you
> have functions that need to reset the shared_ptr itself.
Jim, this is the best write-up on the shared_ptr support I read _in all the
years_. The above matches my current mental model of the topic, but it took
me a long time to understand this. The custom deleter part (rarely mentioned
and probably not well known even among shared_ptr users) is absolutely crucial
information to people with a solid C++ (and Python) background trying to
understand BPL behavior in this respect. Looking forward to you improving the
docs. :-)
Best,
Hans
_______________________________________________
Cplusplus-sig mailing list
Cplusplus-sig@python.org
http://mail.python.org/mailman/listinfo/cplusplus-sig
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic