Opened 11 years ago

Closed 9 years ago

Last modified 9 years ago

#5690 closed Patches (fixed)

intrusive_ptr detach method

Reported by: nn-mail@… Owned by: Peter Dimov
Milestone: To Be Determined Component: smart_ptr
Version: Boost 1.47.0 Severity: Optimization
Keywords: intrusive_ptr Cc:

Description

It is very handy. In some cases like passing between threads or between functions.

(e.g. Boost.ASIO needs this too)

Instead of writing this code:

intrusive_ptr<A> a(get_a());

intrusive_add_ref(a.get());
call(a.get());

One could write

intrusive_ptr<A> a(get_a());

call(a.detach());

The good thing in the second variation that we don't increase counter, so no 'lock' opcode to the processor. Better performance.

Patch:

        void* detach()
        {
                T * tmp = px;
                px = 0;
                return tmp;
        }

Thanx.

Attachments (1)

0001-Add-intrusive_ptr-detach.patch (3.3 KB ) - added by avi@… 9 years ago.
Improved patch (test + docs)

Download all attachments as: .zip

Change History (4)

by avi@…, 9 years ago

Improved patch (test + docs)

comment:1 by Peter Dimov, 9 years ago

Resolution: fixed
Status: newclosed

comment:2 by NN, 9 years ago

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 ?

comment:3 by Peter Dimov, 9 years ago

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.

Note: See TracTickets for help on using tickets.