Circular Buffers
A circular buffer that will automatically increase in size as necessary as data is pushed to the front or back.
Deprecated since version 30.1: Replaced by Double-Ended Queue
#include <util/circlebuf.h>
Circular Buffer Structure (struct circlebuf)
-
struct circlebuf
Circular Buffer Inline Functions
-
void circlebuf_init(struct circlebuf *cb)
Initializes a circular buffer (just zeroes out the entire structure).
- Parameters:
cb – The circular buffer
-
void circlebuf_free(struct circlebuf *cb)
Frees a circular buffer.
- Parameters:
cb – The circular buffer
-
void circlebuf_reserve(struct circlebuf *cb, size_t capacity)
Reserves a specific amount of buffer space to ensure minimum upsizing.
- Parameters:
cb – The circular buffer
capacity – The new capacity, in bytes
-
void circlebuf_upsize(struct circlebuf *cb, size_t size)
Sets the current active (not just reserved) size. Any new data is zeroed.
- Parameters:
cb – The circular buffer
size – The new size, in bytes
-
void circlebuf_place(struct circlebuf *cb, size_t position, const void *data, size_t size)
Places data at a specific positional index (relative to the starting point) within the circular buffer.
- Parameters:
cb – The circular buffer
position – Positional index relative to starting point
data – Data to insert
size – Size of data to insert
-
void circlebuf_push_back(struct circlebuf *cb, const void *data, size_t size)
Pushes data to the end of the circular buffer.
- Parameters:
cb – The circular buffer
data – Data
size – Size of data
-
void circlebuf_push_front(struct circlebuf *cb, const void *data, size_t size)
Pushes data to the front of the circular buffer.
- Parameters:
cb – The circular buffer
data – Data
size – Size of data
-
void circlebuf_push_back_zero(struct circlebuf *cb, size_t size)
Pushes zeroed data to the end of the circular buffer.
- Parameters:
cb – The circular buffer
size – Size
-
void circlebuf_push_front_zero(struct circlebuf *cb, size_t size)
Pushes zeroed data to the front of the circular buffer.
- Parameters:
cb – The circular buffer
size – Size
-
void circlebuf_peek_front(struct circlebuf *cb, void *data, size_t size)
Peeks data at the front of the circular buffer.
- Parameters:
cb – The circular buffer
data – Buffer to store data in
size – Size of data to retrieve
-
void circlebuf_peek_back(struct circlebuf *cb, void *data, size_t size)
Peeks data at the back of the circular buffer.
- Parameters:
cb – The circular buffer
data – Buffer to store data in
size – Size of data to retrieve
-
void circlebuf_pop_front(struct circlebuf *cb, void *data, size_t size)
Pops data from the front of the circular buffer.
- Parameters:
cb – The circular buffer
data – Buffer to store data in, or NULL
size – Size of data to retrieve
-
void circlebuf_pop_back(struct circlebuf *cb, void *data, size_t size)
Pops data from the back of the circular buffer.
- Parameters:
cb – The circular buffer
data – Buffer to store data in, or NULL
size – Size of data to retrieve