libGimbal 0.1.0
C17-Based Extended Standard Library and Cross-Language Runtime Framework
Loading...
Searching...
No Matches
gimbal_ring_buffer.h File Reference

Go to the source code of this file.

Data Structures

struct  GblRingBuffer
 

Macros

#define GblRingBuffer_construct(...)
 

Functions

GBL_RESULT GblRingBuffer_construct_6 (GblRingBuffer *pSelf, uint16_t elementSize, size_t capacity, size_t initialSize, const void *pInitialData, GblContext *pCtx)
 
GBL_RESULT GblRingBuffer_construct_5 (GblRingBuffer *pSelf, uint16_t elementSize, size_t capacity, size_t initialSize, const void *pInitialData)
 
GBL_RESULT GblRingBuffer_construct_4 (GblRingBuffer *pSelf, uint16_t elementSize, size_t capacity, size_t initialSize)
 
GBL_RESULT GblRingBuffer_construct_3 (GblRingBuffer *pSelf, uint16_t elementSize, size_t capacity)
 
GBL_RESULT GblRingBuffer_destruct (GblRingBuffer *pSelf)
 
GBL_RESULT GblRingBuffer_copy (GblRingBuffer *pSelf, const GblRingBuffer *pOther)
 
GBL_RESULT GblRingBuffer_move (GblRingBuffer *pSelf, GblRingBuffer *pOther)
 
GblContextGblRingBuffer_context (const GblRingBuffer *pSelf)
 
size_t GblRingBuffer_capacity (const GblRingBuffer *pSelf)
 
size_t GblRingBuffer_size (const GblRingBuffer *pSelf)
 
size_t GblRingBuffer_elementSize (const GblRingBuffer *pSelf)
 
GblBool GblRingBuffer_empty (const GblRingBuffer *pSelf)
 
GblBool GblRingBuffer_full (const GblRingBuffer *pSelf)
 
void * GblRingBuffer_at (const GblRingBuffer *pSelf, size_t index)
 
void * GblRingBuffer_front (const GblRingBuffer *pSelf)
 
void * GblRingBuffer_back (const GblRingBuffer *pSelf)
 
GBL_RESULT GblRingBuffer_pushBack (GblRingBuffer *pSelf, const void *pData)
 
void * GblRingBuffer_emplaceBack (GblRingBuffer *pSelf)
 
void * GblRingBuffer_popFront (GblRingBuffer *pSelf)
 
void GblRingBuffer_clear (GblRingBuffer *pSelf)
 

Detailed Description

GblRingBuffer container and related functions.

Contiguous, array-based circular/ring buffer with queue semantics.

GblRingBuffer is a generic container of fixed capacity, to which elements may be enqueued or dequeued without requiring any shuffling around in memory. Rather than resizing when the capacity is reached, any new values simply overrwrite the oldest values. Insertions and removals are performed semantically like a queue: pushing to the back and popping from the front; however, since the container is implemented as a contiguous array, it is also randomly accessible.

Operation Time Complexity
iteration O(N)
insertion (back) O(1)
removal (front) O(1)
access (front or back) O(1)
random access (middle) O(1)

These properties make this structure well-suited for FIFO or queue style structures of fixed sizes as well as for representing stream buffers in memory, where a producer is pushing new entries while a consumer pops them.

See also
GblDeque, GblArrayList
Todo:
  • since nothing is public, make it an opaque struct with its buffer appended to the end of the same allocation
Author
Falco Girgis

Definition in file gimbal_ring_buffer.h.

Macro Definition Documentation

◆ GblRingBuffer_construct

#define GblRingBuffer_construct (   ...)

Definition at line 85 of file gimbal_ring_buffer.h.