Circular buffer
Last updated
Last updated
To quickly start with circular buffers:
Find the Functions
panel on the left-hand side of the screen.
Expand Utilities
and then Circular Buffer.
Create a buffer instance with the create function.
Expand the instance that appeared in the panel and get started with using the buffer.
Use the create
and delete
functions to manage the existing circular buffers. 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.
To create
a circular buffer:
Insert a new name in the yellow field.
Insert a capacity in integer form in the second field.
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
To delete
a buffer:
Insert the name of an existing buffer in the yellow field.
Click the trigger field.
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.
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.
getSize
returns the amount of values currently saved inside the buffer.
getCapacity
returns the maximum number of values storable in the buffer.
getBuffer
returns the content of the circular buffer as an object.
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.
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.
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.
With popBack
you can get the last entry in the buffer returned. The entry is deleted upon triggering this function.