Talking about "Stack and stack"
Some new users may not understand what Stack and stack are. Here I will give a brief introduction:
When the program is running, its data must be stored in the memory. The size of memory required for a data item, where it is stored, and how it is stored depend on the data item type.
The running program uses two memory areas to store data: Stack and heap.
First, what is "stack "?
Stack is a memory array and a data structure of LIFO (last-in first-out, last-in first-out. Stack stores several types of data:
- Values of some types of Variables
- Current execution environment of the program
- Parameters passed to the Method
Stack features:
Stack has the following common features:
- Data can only be inserted and deleted from the top of the stack.
- Putting data on the top of the stack is called push)
- Deleting data from the top of the stack is called pop)
What is "heap "?
A heap is a memory area. A large block of memory can be allocated in the heap to store certain types of data. Unlike the stack, the memory in the stack can be stored and removed in any order.
Although programs can save data in the heap, they cannot be deleted explicitly. The automatic GC (Garbage Collector) of CLR determines
The code will no longer access a data item, so it will automatically clear helpless heap objects. Therefore, we can no longer worry about this very error-prone job when using other programming languages.
Stack space allocation:
Stack (operating system): the operating system automatically assigns release, stores function parameter values, local variable values, and so on. The operation method is similar to the stack in the data structure. Heap (operating system): Generally, it is assigned and released by the programmer. If the programmer does not release the program, it may be recycled by the OS at the end of the program. The allocation method is similar to the linked list.
In short: heap, queue first, first-in-first-out, stack, first-out, and stack access speed is faster than heap.