Creating a non-thread safe shared_ptr

Viewed 3774

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'

6 Answers
Related