Ring Buffer

About

Can be seen as Arrays that have a defined head and tail property.

You work inserting data in the middle of this Array which we will call Buffer. And you may insert in the head or in the tail, meaning these properties will end up creating an abstract Array inside this Buffer.

Drawing

Once the tail reach N size you then tail % N, and make it ring around to the begining.

When tail = head then the buffer is full and must grow.

circle-info

They are good if you need a DS that maintains order, but have data being flushed periodicaly, and want your memory allocation to be stable and not spiking from time to time.

Like a data structure to maintin logs.

Last updated