What are the functions of heap, stack, free storage area, global/static storage area and constant storage area?

Heap, stack, free storage area, global/static storage area and constant storage area
In C++, memory is divided into 5 areas, they are heap, stack, free storage area, global/static storage area and constant storage area.

 
The stack is the storage area for variables that are allocated by the compiler when needed and automatically cleared when not needed. The variables inside are usually local variables, function parameters, etc.

 
The heap is the memory block allocated by new. Their release compiler does not care, but is controlled by our application. Generally, a new corresponds to a delete. If the programmer does not release it, the operating system will automatically reclaim it after the program ends. 


The free storage area is those memory blocks allocated by malloc etc. It is very similar to the heap, but it uses free to end its life. 


Global/static storage area, global variables and static variables are allocated to the same block of memory. In the previous C language, global variables are divided into initialized and uninitialized. There is no such distinction in C++. They share the same A memory area. 


Constant storage area, this is a relatively special storage area. They store constants and are not allowed to be modified (of course, you can also modify them through improper means, and there are many methods. In the article "Thinking about const", I 6 methods are given) Clearly distinguish between heap and stack 

Guess you like

Origin blog.csdn.net/txwtech/article/details/106841892