This question already has an answer here:
-
Why are the terms “automatic” and “dynamic” preferred over the terms “stack” and “heap” in C++ memory management?
6 answers
Just what the title says, "What is the technical definition of dynamic storage in C++?" I'm curious as to how to discuss dynamic memory allocation on the heap without making any mistakes in my explanation.
From the The C++ Programming Language: Special Edition
Free store, from which memory for objects is explicitly requested by
the program and where a program can free memory again once it is done
with it (using new
and delete
). When a program needs more free
store, new
requests it from the operating system. Typically, the
free store (also called dynamic memory
or the heap) grows throughout the lifetime of a program because no
memory is ever returned to the operating system for use by other
programs.
Detailed Explaination
The heap is a bunch of memory that can be used dynamically.
Lets say you want 12kb of memory for an object then the dynamic allocator will look through its list of free space in the heap, pick out a 12kb chunk, and give it to you.
Generally, the dynamic memory allocator (malloc, new, etc.) starts at the end of memory and works backwards.