News for hackers. Stuff that matters.
Re:Three kinds of memory leaks by quietbritishjim on Tuesday May 01, 2018 @04:35AM (#16965419)
Responding to a suggestion to use smart pointers with a suggestion to RAII instead doesn't make sense because smart pointers are themselves an example of RAII. I assume what you meant was using stack allocations to avoid heap allocations except (presumably) via library containers like the STL.

This is a good idea where it can be done, and it's worth noting that move semantics replace some uses where a unique pointer would've have been necessary pre-C++11. But there are plenty of applications where it's really not possible. A big one is that if you're using inherence and virtual methods (out of fashion though they are) then you'll almost certainly need a pointer. Plenty of large complex applications cannot avoid object lifetimes with complex rules, which shared pointers track nicely, usually because objects are shared between threads or network requests. For example, if you're using ASIO (which is the basis of standard library networking in C++20) it's hard to imagine how you'd avoid using shared pointers.

There are no comments on this comment yet.