Personal summary:
1 location is different: Stack and stack are in different locations in the memory, stack is in high address, stack is in low address
2. different purposes: Stack is applied by the system, and stack is applied by programmers.
3. Different recycling methods: the stack is released by the system itself, and must be manually released by the programmer before the program ends.
4. Different Sizes: the stack usually has a relatively small capacity and the heap memory capacity is relatively large.
Attached memory distribution knowledge:
The memory occupied by a c/C ++ compiled program is divided into the following parts:
1. stack: the stack zone is automatically allocated and released by the compiler, and stores function parameter values and local variable values. The operation method is similar to the stack in the data structure.
2. heap-generally assigned and released by the programmer. If the programmer does not release the heap, it may be recycled by the OS at the end of the program. Note that it is different from the heap in the data structure. The allocation method is similar to the linked list.
3. Global (static)-the storage of global variables and static variables is put together, and the initialized global variables and static variables are in one area, uninitialized global variables and uninitialized static variables are in another adjacent area. -The system is released after the program ends.
4. Text Constant Area-constant strings are placed here. The program is released by the System
5. program code area-stores the binary code of the function body