C++ Memory Model

Type
Explainer
Updated

Memory Model

Variables can either be created or destroyed. They can also exist on different locations (i.e the stack, heap or static storage).

Memory regions of a C++ program from top to bottom: stack for function calls and local variables, heap for dynamic allocation, static storage for global and static variables, and code (text) for compiled instructions.

Go into the roles played by each of these memory segments.

However, in C++ it is important to resolve this question in any code that we write:

Who is responsible for cleaning up this piece of memory?

Data Structures

We have std::array and std::string instead of just the basic structures provided in the C language. These are safer abstractions which reduces the need for manual pointer juggling.

Type to search every note and essay.