Talking about "Stack and stack"

Source: Internet
Author: User

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.

 

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.