What is the difference between memory, buffer and stack?

16,542

Solution 1

A buffer temporarily stores data while the data is the process of moving from one place to another, i.e. 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

Solution 2

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.

Share:
16,542

Related videos on Youtube

rullof
Author by

rullof

Updated on September 15, 2022

Comments

  • rullof
    rullof over 1 year

    While learning C programming only the memory is mentioned, but in practice it seems that there is more; the buffer and stack words are also used.

    What is the difference between these terms? Why are they relevant?

    Please, I need a detailed answer. Short answers can't serve. Also some resources may be helpful.

    • J3STER
      J3STER about 7 years
      if this question was asked 7 years ago, it would have tons of upvotes, the hypocricy of this site is astonishing
  • Fiddling Bits
    Fiddling Bits over 10 years
    You teaching @rullof how to search the internet? ;-)
  • Rahul Tripathi
    Rahul Tripathi over 10 years
    @FiddlingBits:- When you see lines like Please, i need a detailed answer. Short answers can't serve. in question then you dont have the alternative other than this ;)
  • rullof
    rullof over 10 years
    @RahulTripathi Tanks. Good with buffer. For the stack i know what is the principle of LIFO but i don't know what it has to do with program and the processing, what's the important to know about it.
  • Rahul Tripathi
    Rahul Tripathi over 10 years
    @rullof:- Although I didnt get your point very clearly but I would tell you that IIRC compilers use stacks when checking things like if/else . Also commands in programming language like recursive method calls use a stack to order or precedence for each call