4 ms·
I hope this is a joke: the std::weak_ptr / std::shared_ptr combo (only non-reference alternative I can think of other than std::optional) can have pretty bad pe
by berkut 9y ago
I hope this is a joke: the std::weak_ptr / std::shared_ptr combo (only non-reference alternative I can think of other than std::optional) can have pretty bad performance implications due to ref-counting atomics in multi-threaded scenarios...
For the use-case of optional pointers that don't have any ownership (and can possibly be updated mid-lifetime) and have a guaranteed external lifetime, what's the alternative?
Are there any other ways of doing this that are guaranteed to have no performance (time or memory) overhead in modern C++ (relying on by-value move semantics isn't ideal) ?
Also, what about std:atomic (CAS) raw pointers - for high-performance / lockless stuff, they can be critical...
- mehwoot 9y agoFor the use-case of optional pointers that don't have any ownership (and can possibly be updated mid-lifetime) and have a guaranteed external lifetime Those three things seem like a pretty rare co-occurrence, if something has no ownership how can it have guaranteed external lifetime without being reference counted? I guess it's possible but in any scenario I come up with reference counting seems an easier way to do it.