I'm working on a mult-threaded program, but have a UI component that makes extensive use of std::shared_ptr to manage elements. I can guarantee that only one thread will ever use these shared_ptrs.
Is there a way to define a shared_ptr that doesn't incur the overhead of thread safe reference counting?
It could be based on boost::shared_ptr or std::shared_ptr.
EDIT: Thanks for answers mentioning intrusive_ptr. I neglected to mention that I also need weak_ptr functionality so that rules it out.
UPDATE: The answer for me is to use local_shared_ptr from Boost. See comment from 'he rambled'
Andrei Alexandrescu talked about implementing your own single threaded shared pointer class (with some additional optimizations) at the CppCon 2014
See the video here
And the slides here
I really think the standard or boost should supply a template parameter for using atomic ref counting in their shared ptrs though...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With