关于C#:内存,缓冲区和堆栈有什么区别?

What is the difference between memory, buffer and stack?

本问题已经有最佳答案,请猛点这里访问。

在学习C语言编程时,只提到了memory,但在实践中,似乎更多的是使用bufferstack两个词。

这些术语有什么区别?它们为什么相关?

拜托,我需要一个详细的答案。简短的回答不起作用。还有一些资源可能会有所帮助。


当数据从一个地方移动到另一个地方(即输入设备到输出设备)的过程中,缓冲区临时存储数据。可以说缓冲区是内存的一部分。可以说,缓冲区是内存中预先分配的区域,在这里您可以在处理数据时存储数据。

从这里:

The buffer, on the other hand, is found mainly in the RAM and acts as
an area where the CPU can store data temporarily. This area is used
mainly when the computer and the other devices have different
processing speeds. Typically, the data is stored in a buffer as it is
retrieved from an input device (such as a mouse) or just before it is
sent to an output device (such as speakers). However, the buffer may
also be used when moving data between processes within a computer.

So, the computer writes the data up into a buffer, from where the
device can access the data, as its own speed. This allows the computer
to be able to focus on other matters after it writes up the data in
the buffer; as oppose to constantly focus on the data, until the
device is done.

Buffers can be implemented in a fixed memory location in hardware or
by using a virtual data buffer in software, which points to a data
buffer are stored on a physical storage medium. Majority of the
buffers are utilized in the software. These buffers typically use the
faster RAM to store temporary data, as RAM has a much faster access
time than hard disk drives. A buffer often adjusts timing by
implementing a queue or FIFO algorithm in memory. Hence, it is often
writing data into the queue at one rate and reading it at another
rate.

堆栈是一组项的集合,在这些项中,数据从称为堆栈顶部的一端插入和删除。

In computer science, a stack is a particular kind of abstract data
type or collection in which the principal (or only) operations on the
collection are the addition of an entity to the collection, known as
push and removal of an entity, known as pop


内存是一种存储空间,其中存储有关程序的指令和数据。缓冲区和堆栈都是内存的一小部分。

缓冲区在执行程序时临时存储数据。

操作系统概念(第8版):

A buffer is memory area that stores data being transferred between two devices or between a device and an application.

另一方面,堆栈是根据后进先出(LIFO)原则插入和移除对象的容器。在下推堆栈中,只允许两个操作:将项推入堆栈,然后将项弹出堆栈。堆栈是一种有限的访问数据结构-只能在堆栈顶部添加和删除元素。push向堆栈顶部添加一个项,pop从顶部删除该项。