7. Memory partition: global area, heap area, stack area, constant area, code area

Insert image description here

Code area: stores the program code, that is, the machine instructions executed by the CPU, and is read-only.
Constant area: stores constants (amounts that cannot be changed while the program is running, for example: 10, string constant "abcde", array name, etc.).
Static area (global area): The storage areas of static variables and global variables are together. Once the memory in the static area is allocated, the memory in the static area will not be released until the program ends.
Heap area: The programmer calls the malloc() function to actively apply for it. The free() function needs to be used to release the memory. If you apply for heap area memory and then forget to release the memory, it is easy to cause Memory leak. The heap area is generally relatively large, with hundreds of megabytes or even 1G, which is dozens or hundreds of times larger than the stack area. The heap address is from low address to high address.
Stack area: stores local variables, formal parameters and function return values ​​within the function. After the scope of the data in the stack area has passed, the system will reclaim the memory in the stack area automatically (allocate memory, reclaim memory), and developers do not need to manually manage it. The inn area is like an inn, with many rooms in it. Rooms are automatically assigned after guests arrive. The guests in the room can be changed, which is a dynamic data change. The stack area is generally relatively small, only a few megabytes to tens of megabytes.

Guess you like

Origin blog.csdn.net/qq_43847153/article/details/126644942