C++ Smart Pointers
The cluster debates the safety, performance, and idiomatic use of smart pointers like shared_ptr and unique_ptr versus raw pointers in modern C++, including RAII, memory management risks, and whether they fully solve correctness issues.
Activity Over Time
Top Contributors
Keywords
Sample Comments
What are the main correctness risks in C++ if you just never use a raw pointer?
"folks it's ok, we're using shared_ptr's. We're safe. Problem solved."
How is a C implementation of std::shared_ptr safer?
Can you give an example of unique_ptr being too heavy?
If you think the problem with C++ is that shared_ptr exists, you should probably just use C.
Doesn't using C++ RAII eliminate some of that? Or you use raw pointers often?
Unless you modified an existing or wrote a new C++ compiler, no, you haven't really (don't forget what you're piggy-backing on when the compiler is invoking ctors and dtors for you too). Boost shared pointers are toys; they don't deal with copy-on-write semantics. C++ exception safety is also hilariously difficult to get right (this adds to the refcounting problem); the language is broken by design.
Javascript isn't to blame: bad C++ is. It is 2021 and if you are not putting things in smart pointers, you are doing it wrong.
What would be the detrimental effect of using smart pointers?
If only unique_ptr makes the whole experience so much better