C # understand "stack" and "stack ",
1. What is stack?
Stack is a memory array, which is a back-to-first-out data structure;
Data Types:
1. Values of some types of variables;
2. Current execution environment of the program;
3. parameters passed to the method;
Common features:
1. data can only be inserted and deleted from the top of the stack;
2. Place data on the top of the stack to become an in-stack;
3. delete data from the top of the stack to become an out-of-stack;
2. 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 objects;
Heap features:
1. Memory in the heap can be stored and removed in any order;
2. data stored in the heap cannot be deleted explicitly;
3. The automatic GC (Garbage Collector) of CLR determines and automatically clears the non-master heap object and releases it;
4. The memory of the released object can be reused;
3. What is the difference between stack and stack?
1. Different data types are stored;
2. The stack can only be inserted and deleted from the top, and the stack can be stored and removed in any order;
3. stack memory does not need to be managed or managed by GC. When the top element of the stack is used up, it is immediately released. While the heap requires GC (Garbage collection: Garbage Collector) cleaning;
4. the stack is automatically allocated by the system, which is faster. But cannot be controlled. Heap is the memory blocks allocated by new. Their release compilers are not controlled by our applications, which are generally slow and prone to memory fragments;
4. In fact, there is no need to investigate in depth what is "heap" and "stack". They are both a piece of memory and are used to store data.