# 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.

<img src="https://977358640-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgbsUv4FfxUwe5ihs1aG5%2Fuploads%2FNPFYYfeg2WHbXGkycsw2%2Ffile.excalidraw.svg?alt=media&#x26;token=d5da6edf-1a49-4beb-b9f4-671cca64ec69" alt="" class="gitbook-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.

{% hint style="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.*
{% endhint %}
