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?
No, queue refers to command and response queues, buffers refer to in-flight data buffers.
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.
Ring Buffer (or Circular Buffer) is a bounded circular data structure that is used for buffering data between two or more threads.
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'.
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.
Have a look at this article by Jakob Jenkov for more details.
Have a look at related SE question :
Java - Ring Buffer
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With