C # understand & quot; stack & quot; and & quot; stack & quot ;,

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.