The concepts exist, yes. The problem is that hundreds of millions of people worldwide have an abstraction leak in their brains when it comes to naming these concepts, and this has spread to the C++ world.
Sometimes, when C++ people talk about "stack" and "heap", they are discussing logical memory storage locations in hardware. It's generally a gross over-simplification in a world of registers, and optimisations, and caching. But there's a grounding in logic there.
Most of the time, though, they're simply using inaccurate synonyms for "automatic storage duration" and "dynamic storage duration", perpetuated by decades of misunderstanding and an inability or resistance to thinking in terms of abstractions.
C++ is an abstraction. It very deliberately defines an abstract machine, and the only way the standard even approaches this topic is to discuss the storage duration of objects. If you declare a local variable, it has automatic storage duration, which means it'll be destroyed when it goes out of scope. It may go into a "stack" on your executing computer, or someplace else if the computer works some other way, or it may not even escape the compilation phase! But people still will insist on saying that this variable is "on the stack" because they think doing so is somehow simpler. That's their right, I suppose, but they're still objectively wrong.
Similarly, when writing std::make_unique<T>(args...)
(or new T(args...)
) you are creating an object of dynamic storage duration, whose lifetime escapes the immediate scope and will only be destroyed when the std::unique_ptr
dies (or when you use delete
). These generally won't be optimised out, but there's no way of knowing whether the physical target platform will use a "heap" data structure to implement what C++ calls the free store. If you have a C++ implementation running on an orange, for example, then it seems unlikely.
So, in conclusion, if you use the terms "on the stack" and "on the heap", then you'll be understood by many but derided by some. The C++ standard is one of those sensible few, and doesn't use these terms at all.