Difference between a ring buffer and a queue

Aravind Yarram picture Aravind Yarram · Apr 16, 2014 · Viewed 11.6k times · Source

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?

Answer

Ravindra babu picture Ravindra babu · Feb 2, 2016

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