Profiling some code that uses shared_ptrs heavily, I found that reset () was unexpectedly expensive.
For instance:
struct Test { int i; Test() { this->i = 0; } Test(int i) { this->i = i; } } ; ... auto t = make_shared<Test>(1); ... t.reset(somePointerToATestObject);
Tracking reset () on the last line (in VC ++ 2010), I found that it was creating a new reference counting object.
Is there a cheaper way that reuses an existing link count and doesn't bother a bunch?
source share