C ++ memory allocation methods-heap, stack, free storage, global/static storage, and constant Storage
Stack is the storage area for variables allocated by the compiler when needed and automatically cleared when not needed. The variables are usually local variables and function parameters. In a process, the user stack is located at the top of the user's virtual address space, and the compiler uses it to call functions. Heap is the memory blocks allocated by new. Their release compilers are not controlled and controlled by our applications. Generally, a new compiler corresponds to a delete. If the programmer does not release the program, the operating system will automatically recycle it after the program is completed. The heap can be dynamically expanded and reduced. The free storage zone is the memory blocks allocated by malloc and so on. It is very similar to the heap, but it uses free to end its own life. In the global/static storage area, global variables and static variables are allocated to the same memory. In the previous C language, the global variables are divided into initialized and uninitialized (the initialized global variables and static variables are in one area, and the uninitialized global variables and static variables are in another adjacent area, objects that are not initialized at the same time can be accessed and manipulated through void *, and are released by the system after the program ends. This distinction is not found in C ++, they share the same memory zone. Constant storage area, which is a special storage area. It stores constants and cannot be modified (of course, you can modify them by improper means, and there are many methods)