Data Structure
1. Heap: FIFO (Fifo-first in First out)
2, Stack: Advanced Back (Filo-first in the last out)
C + +
The memory consumed by a compiled program is divided into the following sections:
1. Stack (stack)-Automatically allocated by the compiler to release, the name of the parameter that holds the function, the name of the local variable, and so on. It operates in a manner similar to a stack in a data structure.
2. Heap area-allocated by the programmer to release, if the programmer does not release, the end of the program may be recycled by the OS. It is different from the heap in the data structure and is distributed in a similar way to a linked list.
3. Static zone-the storage of global variables and local static variables is placed in one piece. Released by the system after the program is finished.
4, literal constant area-the constant string is placed here, the program is released after the end of the system.
5. Program code area-binary code that holds the function body.
Java
1. Stack (stack) and heap are the places that Java uses to store data in RAM. Unlike C + +, Java automatically manages stacks and heaps, and programmers cannot directly set up stacks or heaps.
2, the advantage of the stack is that the access speed is faster than the heap, second only to the register directly in the CPU. However, the disadvantage is that the size and lifetime of the data in the stack must be deterministic and inflexible. In addition, stack data can not be shared between multiple threads or multiple stacks, but multiple variables with equal values within the stack can point to an address. The advantage of the heap is that the memory size can be allocated dynamically, and the lifetime does not have to tell the compiler beforehand that the Java garbage collector automatically collects the data that is no longer in use. However, the disadvantage is that the access speed is slower due to the dynamic allocation of memory at run time.
Heap & Stack