Introducing heaps and stacks in C #

Source: Internet
Author: User
1. What is a heap?

A heap is an area of memory in which large chunks of memory can be allocated for storing data objects of a certain type;

Characteristics of the heap:

1. The memory inside the heap can be deposited and removed in any order;

2, can not be displayed to delete the program in the heap stored data;

3, by the CLR's automatic GC (garbage collector) to determine and automatically clear the non-Master heap object, and then release it;

4, the memory of the freed object can be reused;

2, what is the stack?

Stack is an array of memory, is a last-in-first-out data structure;

Several data types:

1, the value of certain types of variables;

2, the current execution environment of the program;

3, the parameters passed to the method;

Several common features:

1, data can only be inserted and deleted from the top of the stack;

2, put the data on the top of the stack into the stack;

3, from the top of the stack to delete data into the stack;

3, stack and heap what difference?

1, the data types of storage are different;

2, the stack can only be inserted and deleted from the top, the heap can be stored in any order and removal;

3, stack memory is not managed, nor is it managed by GC. When the top element of the stack is finished, it is released immediately. The heap requires a GC (garbage collection: garbage collector) cleanup;

4, the stack is automatically assigned by the system, the speed is faster. But there is no control. The heap is those allocated by new memory blocks, their release compiler does not go to the tube, by our application to control, generally slow, and easy to produce memory fragmentation.
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.