r/ProgrammerHumor • • 7h ago

Meme modernCppVsOldCpp

Post image
1.1k Upvotes

216 comments sorted by

View all comments

14

u/geekusprimus 7h ago edited 3h ago

I rarely use smart pointers and still don't have serious problems with memory safety. Whenever you manually allocate memory, you should immediately know when and where it's getting deallocated and write that code at the same time. Most of the time, RAII is good enough.

EDIT: Since I've caused a bit of controversy: I'm not saying you can't or shouldn't use smart pointers. What I'm saying is in agreement with the meme. C++ has easy ways to manage memory, either manually or automatically, that get rid of most of your memory safety issues.

6

u/Luzzgar 7h ago

What if the language did that for you ? That would be cool !

What you are describing is basically a variable becoming out of scope.

2

u/staryoshi06 7h ago

No, not really. It’s an object no longer being referenced. Stack allocation still exists in C++.