5 ms·
[referring to unreachable allocations] > If you’re writing in C or C++, especially C++ without ubiquitous use of smart pointers to manage memory lifetimes, thi
by banachtarski 8y ago
[referring to unreachable allocations]
> If you’re writing in C or C++, especially C++ without ubiquitous use of smart pointers to manage memory lifetimes, this is your first guess.
What absolute rubbish. Ever heard of a constructor/destructor (aka RAII)? You can go really far without the usage of any new/delete or a smart pointer, and this probably should be the case all the way up till the OS boundary.
- golergka 8y agoMost of the time, RAII is a good idea. Not always, though. https://www.google.ru/url?sa=t&source=web&rct=j&url=%23&ved=0ahUKEwi5js_0iuTaAhVC4YMKHWv7C5AQxa8BCCUwAA&usg=AOvVaw0VTJzWxrN8ZFOD4xbU2nov https://www.google.ru/url?sa=t&source=web&rct=j&url=%23&ved=... (Sorry for weird url, YouTube seems to be currently blocked here and I'm too lazy to wait for a VPN connection).
- chrismorgan 8y agoThat URL doesn’t work at all—just redirects to #.
- golergka 8y agoIt was to Jonathan's Blow presentation for ideas about a language for game programming, where he goes in depth about RAII, C/C++, Go, Rust and other modern language developments.
- quietbritishjim 8y agoResponding 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.
- geofft 8y agoHow do you implement a tree or a linked list without using new/delete or smart pointers?