13. Circular queue

This is a particular kind of queue where new items are added to the rear of the queue as items are read off the front of the queue. So there is constant stream of data flowing into and out of the queue.

Another name for it is 'circular buffer.

circular buffer queue

The diagram above shows items entering the queue at the rear whilst the item at the front of the queue is read (and removed)

Normally, one process is writing items into the queue and a different process is reading items from the queue.

Example: Burning a DVD

When burning a DVD it is essential that the laser beam burning pits onto the surface is constantly fed with data, otherwise the DVD fails.

Most leading DVD burn applications make use of a circular buffer to stream data from the hard disk onto the DVD.

The first part, the 'writing process', fills up a circular buffer with data, then the 'burning process' begins to read from the buffer as the laser beam burns pits onto the surface of the disk. If the buffer starts to become empty, the application carefully slows down the burn rate and speeds up the writing rate to avoid 'buffer underflow' i.e. an empty buffer

Advantage of a circular queue

It is a structure that allows data to be passed from one process to another whilst making the most efficient use of memory.

 

 

Copyright © www.teach-ict.com