What is the difference between memory, buffer and stack?

This question already has an answer here:

  • What and where are the stack and heap? 25 answers

  • A buffer temporarily stores data while the data is the process of moving from one place to another, ie the input device to the output device. You can say that buffer is a part of the memory. You can say that a buffer is a pre allocated area of the memory where you can store your data while you are processing it.

    From here:

    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.

    Stack is a collection of items in which the data are inserted and remove from one end called the top of the stack.

    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


    Memory is a storage space where instructions and data, regarding programs, are stored. Buffer and stack both are the small section of the memory.

    Buffer stores data temporarily while execution of the program.

    Operating System Concepts (8th ED):

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

    On the other hand, a stack is a container of objects that are inserted and removed according to the last-in first-out (LIFO) principle. In the pushdown stacks only two operations are allowed: push the item into the stack, and pop the item out of the stack. A stack is a limited access data structure - elements can be added and removed from the stack only at the top. push adds an item to the top of the stack, pop removes the item from the top.

    链接地址: http://www.djcxy.com/p/2258.html

    上一篇: c编程中的stackoverflow的含义

    下一篇: 内存,缓冲区和堆栈有什么区别?