4 ms·
speaking about shared_ptr, they have a reference count that is done as an atomic counter, because you could use the shared_ptr instance from multiple threads, s
by MichaelMoser123 5y ago
speaking about shared_ptr, they have a reference count that is done as an atomic counter, because you could use the shared_ptr instance from multiple threads, so that it has to be as general as possible. Now that atomic counter was not needed in my case, as the objects were only accessed from the same thread; however it had some surprisingly adverse effects on performance, in my projects at least...
i think they should add some template argument to determine if an atomic counter is used or not, exactly for the cases where the shared_ptr object is used exclusively from a single thread; but they didn't do that in the standard.
- MichaelMoser123 5y agoin gcc the shared_ptr is derived from __shared_ptr, where you can pass a lock policy trait that goes without locking. wow. But i am afraid that is implementation specific.