> For the complete documentation index, see [llms.txt](https://docs.heisenware.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.heisenware.com/app-builder/build-backend/function-explorer/storage/circular-buffer.md).

# Circular Buffer

The `Buffer` class implements a circular buffer (also known as a ring buffer), which is a data structure that uses a single, fixed-size buffer as if it were connected end-to-end. When the buffer is full, new elements overwrite the oldest ones. This is useful for managing streams of data where only the most recent items are of interest.

You must create an instance of the buffer with a specified capacity.

***

#### create

Creates a new circular buffer instance with a specified capacity.

Parameters

* `capacity`: The maximum number of items the buffer can hold. Defaults to `100`.

Example

```yaml
# capacity
10
```

***

#### getSize

Returns the current number of items stored in the buffer.

Output

An integer representing the current size of the buffer.

***

#### getCapacity

Returns the maximum number of items the buffer can hold, as specified during creation.

Output

An integer representing the capacity of the buffer.

***

#### getBuffer

Returns all items currently in the buffer as a standard array.

Output

An array containing all values stored in the buffer, ordered from front to back.

***

#### pushFront

Adds an item to the front of the buffer. If the buffer is full, this will overwrite the item at the back.

Parameters

* `value`: The value or object to add to the buffer.

Example

```yaml
# value
New item
```

***

#### pushBack

Adds an item to the back (end) of the buffer. This is the most common "push" operation. If the buffer is full, this will overwrite the item at the front.

Parameters

* `value`: The value or object to add to the buffer.

Example

```yaml
# value
Another new item
```

***

#### popFront

Removes and returns the item from the front of the buffer.

Output

The value that was at the front of the buffer.

***

#### popBack

Removes and returns the item from the back (end) of the buffer.

Output

The value that was at the back of the buffer.

***

#### clear

Empties the buffer, removing all of its contents.

Output

Returns true.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://docs.heisenware.com/app-builder/build-backend/function-explorer/storage/circular-buffer.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
