# Circular buffer

{% hint style="danger" %}
**ATTENTION. THIS CURRENTLY WORKS DIFFERENTLY FROM A CIRCULAR BUFFER ⚠️**\
**READ ESPECIALLY** [**pushFront**](#pushfront)**,** [**pushBack**](#pushback)**,** [**popFront**](#popfront) **and** [**popBack**](#popback)**!**
{% endhint %}

To quickly start with circular buffers:

1. Find the `Functions` panel on the left-hand side of the screen.
2. Expand `Utilities` and then `Circular Buffer.`
3. Create a buffer instance with the [create](#create) function.
4. Expand the instance that appeared in the panel and get started with using the buffer.

Use the [`create`](#create) and [`delete`](#delete) functions to manage the existing [circular buffers](https://en.wikipedia.org/wiki/Circular_buffer). Existing buffers can be seen in the functions panel on the left under `circular buffers`. Yellow ones are uninstantiated and green ones are ready for use.

## Creating a buffer

To `create` a circular buffer:

1. Insert a new name in the yellow field.
2. Insert a capacity in integer form in the second field.
3. Click the trigger field to create an instance of the buffer
   * You should see the buffer in the functions panel go from yellow to green

<div align="center"><figure><img src="/files/v8DhFSIAV95xvFdjbE76" alt="" width="563"><figcaption><p>Create a circular buffer</p></figcaption></figure></div>

## Deleting a buffer

To `delete` a buffer:

1. Insert the name of an existing buffer in the yellow field.
2. Click the trigger field.

<div align="center"><figure><img src="/files/EJhGn7GE3odXUg7jBoWS" alt="" width="370"><figcaption><p>Delete a circular buffer</p></figcaption></figure></div>

{% hint style="info" %}
The instance in the functions panel will turn yellow again, until the yellow field of the `create` function is cleared, or the `create` function is deleted from the board.
{% endhint %}

## Circular buffer functions

To utilize the circular buffer, you can find functions tied to each instance when you expand the instance with a click on the arrow in front of it.

<div align="center"><figure><img src="/files/EU5IPQOptLekSiioyVUH" alt="" width="186"><figcaption><p>Where to find circular buffer instances</p></figcaption></figure></div>

### Retrieving buffer size

`getSize` returns the amount of values currently saved inside the buffer.

<figure><img src="/files/Wq5zVQ0LYnxZvRWtbBxK" alt="" width="375"><figcaption><p>Circular buffer getSize</p></figcaption></figure>

### Retrieving buffer capacity

`getCapacity` returns the maximum number of values storable in the buffer.

<div align="center"><figure><img src="/files/5LTH6ORdNc0Ul4029kYF" alt="" width="375"><figcaption><p>Circular buffer getCapacity</p></figcaption></figure></div>

### Retrieving buffer content

`getBuffer` returns the content of the circular buffer as an object.

<div align="center"><figure><img src="/files/x1uDSY3oWSzTOHgEnoCj" alt="" width="375"><figcaption><p>Circular buffer getBuffer</p></figcaption></figure></div>

### Inserting value in front

`pushFront` inserts a new value at the front, pushing all other values back one slot. When the buffer is full, the values at the back get dropped.

<div align="center"><figure><img src="/files/jctf7k6WTcyaREI5SSbS" alt="" width="375"><figcaption><p>Circular buffer pushFront</p></figcaption></figure></div>

### Inserting value at the end

`pushBack` inserts a new value at the end of the currently existing values. When the buffer is full, new values are inserted at the end and old values get pushed one index to the front. The first entry is thereby deleted every time something is inserted into a full buffer with this function.

<div align="center"><figure><img src="/files/jcbMgwWsW6JE3nOQezlb" alt="" width="375"><figcaption><p>Circular buffer pushBack</p></figcaption></figure></div>

### Retrieving first entry

With `popFront` you can get the first entry in the buffer returned. The entry is deleted upon triggering this function and all other entries move up one index.

<div align="center"><figure><img src="/files/B8fiwQGsbQoEjpn8l8Oj" alt="" width="375"><figcaption><p>Circular buffer popFront</p></figcaption></figure></div>

### Retrieving last entry

With `popBack` you can get the last entry in the buffer returned. The entry is deleted upon triggering this function.

<div align="center"><figure><img src="/files/Hh5ppynT7Ekozg7ct4Jm" alt="" width="375"><figcaption><p>Circular buffer popBack</p></figcaption></figure></div>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.heisenware.com/~/changes/eYCCpn9cCBKOYnZA6a8f/building-apps/data-processing/utilities/circular-buffer.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
