id summary reporter owner description type status milestone component version severity resolution keywords cc
5690 intrusive_ptr detach method nn-mail@… Peter Dimov "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:
{{{
#!cpp
intrusive_ptr a(get_a());
intrusive_add_ref(a.get());
call(a.get());
}}}
One could write
{{{
#!cpp
intrusive_ptr 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:
{{{
#!cpp
void* detach()
{
T * tmp = px;
px = 0;
return tmp;
}
}}}
Thanx." Patches closed To Be Determined smart_ptr Boost 1.47.0 Optimization fixed intrusive_ptr