Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between a ring buffer and a queue

What is the difference between the ring (circular) buffer and a queue? Both support FIFO so in what scenarios I should use ring buffer over a queue and why?

Relevance to Hadoop

The map phase uses ring buffer to store intermediate key value pairs. What are the reasons for this choice over a queue?

like image 219
Aravind Yarram Avatar asked Apr 16 '14 13:04

Aravind Yarram


People also ask

What is the difference between queue and buffer?

No, queue refers to command and response queues, buffers refer to in-flight data buffers.

What is the difference between circular buffer and circular queue?

A Circular Queue is an extension of the Queue data structure such that the last element of the queue links to the first element. It is known as Ring Buffer, Circular Buffer or Cyclic Buffer. In Linear Queue Data Structure, we have two pointers Front and Rear.

What does a ring buffer do?

Ring Buffer (or Circular Buffer) is a bounded circular data structure that is used for buffering data between two or more threads.

Which type of queue is also called as ring buffer?

Circular Queue: Circular Queue is a linear data structure in which the operations are performed based on FIFO (First In First Out) principle and the last position is connected back to the first position to make a circle. It is also called 'Ring Buffer'.


1 Answers

A RingBuffer is an array, which is used as Queue

It will maintain both Read & Write positions separately. When it reach end of Array, it will continue from beginning of Array.

Uses of RingBuffer over Queue.

  1. Ring Buffers are fast.
  2. When you have hard cut-off for how much data to be stored, RingBuffer is useful.

Have a look at this article by Jakob Jenkov for more details.

Have a look at related SE question :

Java - Ring Buffer

like image 177
Ravindra babu Avatar answered Sep 19 '22 19:09

Ravindra babu