MBP 02 - Circular Buffer
MBP 02 - Circular Buffer
Deque q = Deque();
Implement function
insertRear
Circular queue
Declaration
Advantages of circular buffer
Simple logic using array and no complex data structures and logic used
No dynamic allocation or deallocation and no chance of memory leak
and other issues
Best suit for low memory footprint systems or for device drivers
Very fast operations and do not include delay of new and delete
These can be used in applications as well as low level codes in interrupt
handlers and real time systems
Limitations of circular buffer
Circular buffer is a class and it has member variables to hold all the context of
a circular buffer. Circular buffer object should have these member variables
Buff - The member buff points to an array which is a static array of fixed
size or dynamic array of fixed size.
Start - Start will have the value of the starting index or offset of this
queue.
End - End will have the value of the ending index or offset of this queue.
Size - Size will have total number of array elements in the buffer. This
remains constant throughout the execution.
Count - Count says the number of available elements in the queue. It
increases when an element gets added in the queue. It decreases once an
element dequeues from the array.
Empty
Is Empty
Insert item
insert the elements to
make a queue full
front = (front + 1) %
size
deQueue
insert or
enqueue
element 11
enQueue
Display