C++ memory

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 . The compiler does not care about their release, 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 recycle it after the program ends.

 

  The free storage area is the memory block 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 memory. In the previous C language, global variables were divided into initialized and uninitialized. In C++ , there is no such distinction. They occupy the same memory. A block of memory.

 

  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 it through illegal means, and there are many methods,

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324768225&siteId=291194637