Boost C++ Libraries: Ticket #5690: intrusive_ptr detach method https://svn.boost.org/trac10/ticket/5690 <p> It is very handy. In some cases like passing between threads or between functions. </p> <p> (e.g. Boost.ASIO needs this too) </p> <p> Instead of writing this code: </p> <div class="wiki-code"><div class="code"><pre> <span class="n">intrusive_ptr</span><span class="o">&lt;</span><span class="n">A</span><span class="o">&gt;</span> <span class="n">a</span><span class="p">(</span><span class="n">get_a</span><span class="p">());</span> <span class="n">intrusive_add_ref</span><span class="p">(</span><span class="n">a</span><span class="p">.</span><span class="n">get</span><span class="p">());</span> <span class="n">call</span><span class="p">(</span><span class="n">a</span><span class="p">.</span><span class="n">get</span><span class="p">());</span> </pre></div></div><p> One could write </p> <div class="wiki-code"><div class="code"><pre> <span class="n">intrusive_ptr</span><span class="o">&lt;</span><span class="n">A</span><span class="o">&gt;</span> <span class="n">a</span><span class="p">(</span><span class="n">get_a</span><span class="p">());</span> <span class="n">call</span><span class="p">(</span><span class="n">a</span><span class="p">.</span><span class="n">detach</span><span class="p">());</span> </pre></div></div><p> The good thing in the second variation that we don't increase counter, so no 'lock' opcode to the processor. Better performance. </p> <p> Patch: </p> <div class="wiki-code"><div class="code"><pre> <span class="kt">void</span><span class="o">*</span> <span class="nf">detach</span><span class="p">()</span> <span class="p">{</span> <span class="n">T</span> <span class="o">*</span> <span class="n">tmp</span> <span class="o">=</span> <span class="n">px</span><span class="p">;</span> <span class="n">px</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="k">return</span> <span class="n">tmp</span><span class="p">;</span> <span class="p">}</span> </pre></div></div><p> Thanx. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/5690 Trac 1.4.3 avi@… Tue, 03 Dec 2013 17:26:47 GMT attachment set https://svn.boost.org/trac10/ticket/5690 https://svn.boost.org/trac10/ticket/5690 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">0001-Add-intrusive_ptr-detach.patch</span> </li> </ul> <p> Improved patch (test + docs) </p> Ticket Peter Dimov Thu, 26 Dec 2013 16:11:14 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/5690#comment:1 https://svn.boost.org/trac10/ticket/5690#comment:1 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> Applied in <a class="ext-link" href="https://github.com/boostorg/smart_ptr/commit/73153d57971849d6cfd13e2bd1bf2b0c9894797d"><span class="icon">​</span>https://github.com/boostorg/smart_ptr/commit/73153d57971849d6cfd13e2bd1bf2b0c9894797d</a> </p> Ticket NN Thu, 26 Dec 2013 17:24:10 GMT <link>https://svn.boost.org/trac10/ticket/5690#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5690#comment:2</guid> <description> <p> Actually 'release' name is much better, cause we have unique_ptr::release. Didn't think about it.. What do you think about changing the name ? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Peter Dimov</dc:creator> <pubDate>Thu, 26 Dec 2013 17:31:54 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/5690#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5690#comment:3</guid> <description> <p> We decided that detach is a better name than release, both because unique_ptr::release gives you a pointer that you own exclusively, and because of the potential confusion between intrusive_ptr::release and intrusive_ptr_release. </p> </description> <category>Ticket</category> </item> </channel> </rss>