#5690 closed Patches (fixed)
intrusive_ptr detach method
Reported by: | 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)
Change History (4)
by , 9 years ago
Attachment: | 0001-Add-intrusive_ptr-detach.patch added |
---|
comment:1 by , 9 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
comment:2 by , 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 , 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.
Improved patch (test + docs)