On 6/19/07, Jeff Webb &lt;<a href="mailto:jeff.webb@nta-inc.net">jeff.webb@nta-inc.net</a>&gt; wrote:<br>&gt; Let me first say that I am extremely impressed with boost python&#39;s elegant and powerful design.&nbsp;&nbsp;I would not have thought that it was possible to integrate C++ and python code in such a nice manner.&nbsp;&nbsp;Thanks for all the hard work and thoughtful design.
<br>&gt; <br>&gt; I am writing a C++ library from scratch, and I want to develop boost python bindings for it simultaneously.&nbsp;&nbsp;My C++ library will instantiate many small objects that hold references to other objects.&nbsp;&nbsp;I had come up a consistent scheme for managing the objects using C++, but when I started trying to wrap the library using boost, I found that this scheme didn&#39;t mesh well with python&#39;s reference counting form of memory management.&nbsp;&nbsp;After quite a bit of reading, experimentation, and contemplation, it appears to me that using reference-counting smart pointers in C++ would be the most consistent and seamless way to provide a rich python binding for this type of library.&nbsp;&nbsp;Do others agree with this assertion?
<br><br>This is was my experience.<br><br><br>&gt; I wrote a simple test library using shared_ptr objects and found that wrapping it was very natural.&nbsp;&nbsp;Things &#39;just worked&#39; as I would have hoped.&nbsp;&nbsp;The source code for this library is attached to this email as &#39;s_ptr_lib.cpp&#39;.&nbsp;&nbsp;A sample ipython session is shown below.
<br><br>Boost.Python has perfect support for boost::shared_ptr and in some cases to std::auto_ptr<br><br>&gt; Very nice!&nbsp;&nbsp;Unfortunately, I think the overhead of using a shared_ptr will be too high, since my library will instantiate many small objects.&nbsp; 
<br><br>It looks like you know what you are doing, but don&#39;t you think this is a premature optimization?<br><br>&gt; Am I on the right path here?&nbsp;&nbsp;Is it possible to make the intrusive_ptr work as seamlessly as the shared_ptr, or is there some fundamental problem with what I hope to achieve?&nbsp; 
<br><br>It is possible to create code that will work pretty closed to as shared_ptr one. If you search this mailing list you will even find the implementation.<br><br>&gt; Is there some technical reason why this is not already implemented, or is it just that there hasn&#39;t been a need up to this point?&nbsp; 
<br><br>Boost.Python has special code that treats shared_ptr here and there.<br><br>&gt; If I should continue down this path, can someone give me a skeleton of the code I need to write (and how to get it &#39;registered&#39;) to provide all the functionality that exists for the shared_ptr class?
<br>&gt; <br><br>Just search this mailing list for &quot;intrusive_ptr&quot; and you will find many useful posts.<br><br>-- <br>Roman Yakovenko<br>C++ Python language binding<br><a href="http://www.language-binding.net/">
http://www.language-binding.net/</a><br>