Home > Common Problem > body text

What is the function of the stack?

coldplay.xixi
Release: 2020-06-29 10:21:15
Original
20798 people have browsed it

The function of the stack is that the access speed is faster than the heap, second only to the registers directly located in the CPU. All data can be stored or taken out only at the floating end, called the top of the stack. Strictly follow According to the principle of "first in, last out", the element in the middle can only be taken out after the elements in the upper part of the stack [the last ones added to the stack] are removed one by one.

What is the function of the stack?

The role of the stack:

In microcontroller applications, the stack is a special storage area whose main function is temporary Store data and addresses, usually used to protect breakpoints and scenes.

In the computer field, the stack is a concept that cannot be ignored. The stack is a data structure. Stack is a data structure in which data items are arranged in order. Data items can only be inserted and deleted at one end (called the top of the stack).

Stack is a specific storage area or register that has one end fixed and the other floating. The data stored in this storage area is a special data structure.

All data can be deposited or taken out only at one end of the float (called top of the stack). Access is strictly in accordance with the "first in, last out" principle. The elements located in the middle are , it can only be taken out after the elements in the upper part of the stack (those pushed into the stack last) are removed one by one. Opening up an area in the internal memory (random access memory) as a stack is called a software stack; a stack composed of registers is called a hardware stack.

What is the function of the stack?

Extended information:

The advantage of the stack is that the access speed is faster than the heap, second only to the registers directly located in the CPU. But the disadvantage is that the size and lifetime of the data stored in the stack must be determined and there is a lack of flexibility.

In addition, stack data cannot be shared between multiple threads or multiple stacks, but multiple variables with equal values ​​within the stack can point to one address. The advantage of the heap is that it can dynamically allocate memory size, and the lifetime does not need to be told to the compiler in advance. Java's garbage collector will automatically collect the data that is no longer used. But the disadvantage is that due to the need to dynamically allocate memory at runtime, the access speed is slow.

Related learning recommendations: PHP programming from entry to proficiency

The above is the detailed content of What is the function of the stack?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template