libamxc
1.10.3
C Generic Data Containers
|
Data Structures | |
struct | _amxc_rbuffer |
The ring buffer structure. More... | |
Typedefs | |
typedef struct _amxc_rbuffer | amxc_rbuffer_t |
The ring buffer structure. More... | |
Functions | |
int | amxc_rbuffer_new (amxc_rbuffer_t **rb, const size_t size) |
Allocates a ring buffer. More... | |
void | amxc_rbuffer_delete (amxc_rbuffer_t **rb) |
Frees the previously allocated ring buffer. More... | |
int | amxc_rbuffer_init (amxc_rbuffer_t *const rb, const size_t size) |
Initializes a ring buffer. More... | |
void | amxc_rbuffer_clean (amxc_rbuffer_t *const rb) |
Frees the buffer and sets all pointers of the ring buffer structure to NULL. More... | |
int | amxc_rbuffer_grow (amxc_rbuffer_t *const rb, const size_t size) |
Grows the ring buffer. More... | |
int | amxc_rbuffer_shrink (amxc_rbuffer_t *const rb, const size_t size) |
Shrinks the ring buffer. More... | |
ssize_t | amxc_rbuffer_read (amxc_rbuffer_t *const rb, char *const buf, size_t count) |
Reads a number of bytes from the ring buffer. More... | |
ssize_t | amxc_rbuffer_write (amxc_rbuffer_t *const rb, const char *const buf, const size_t count) |
Writes a number of bytes to the ring buffer. More... | |
size_t | amxc_rbuffer_size (const amxc_rbuffer_t *const rb) |
Get the size of the data stored in the ring buffer. More... | |
AMXC_INLINE size_t | amxc_rbuffer_capacity (const amxc_rbuffer_t *const rb) |
Get the capacity of the ring buffer. More... | |
AMXC_INLINE bool | amxc_rbuffer_is_empty (const amxc_rbuffer_t *const rb) |
Checks that the ring buffer is empty. More... | |
typedef struct _amxc_rbuffer amxc_rbuffer_t |
The ring buffer structure.
AMXC_INLINE size_t amxc_rbuffer_capacity | ( | const amxc_rbuffer_t *const | rb | ) |
Get the capacity of the ring buffer.
The capacity is the maximum bytes that can be stored in the ring buffer. The capacity - the size is the number of bytes that is currently not used.
rb | a pointer to the ring buffer structure |
Definition at line 286 of file amxc_rbuffer.h.
void amxc_rbuffer_clean | ( | amxc_rbuffer_t *const | rb | ) |
Frees the buffer and sets all pointers of the ring buffer structure to NULL.
rb | a pointer to the ring buffer structure |
Definition at line 134 of file amxc_rbuffer.c.
void amxc_rbuffer_delete | ( | amxc_rbuffer_t ** | rb | ) |
Frees the previously allocated ring buffer.
Frees the ring buffer, all data that is still in the buffer will be lost. Also frees the allocated memory to store the ring buffer structure and sets the pointer in the structure to NULL.
rb | a pointer to the location where the pointer to the ring buffer is stored |
Definition at line 96 of file amxc_rbuffer.c.
int amxc_rbuffer_grow | ( | amxc_rbuffer_t *const | rb, |
const size_t | size | ||
) |
Grows the ring buffer.
Increases the capacity of the ring buffer with a number of bytes. The extra memory is always allocated behind the current position of the write pointer. Growing the ring buffer has no effect on the data that is already in the ring buffer.
rb | a pointer to the ring buffer structure |
size | the number of bytes the ring buffer has to grow |
Definition at line 147 of file amxc_rbuffer.c.
int amxc_rbuffer_init | ( | amxc_rbuffer_t *const | rb, |
const size_t | size | ||
) |
Initializes a ring buffer.
Initializes the ring buffer structure. Memory is allocated from the heap to be able to store the number of bytes requested.
This function is typically called for ring buffers that are on the stack. Allocating and initializing a ring buffer on the heap can be done using amxc_rbuffer_new
rb | a pointer to the ring buffer structure. |
size | the size of the ring buffer in number of bytes |
Definition at line 107 of file amxc_rbuffer.c.
AMXC_INLINE bool amxc_rbuffer_is_empty | ( | const amxc_rbuffer_t *const | rb | ) |
Checks that the ring buffer is empty.
rb | a pointer to the ring buffer structure |
Definition at line 302 of file amxc_rbuffer.h.
int amxc_rbuffer_new | ( | amxc_rbuffer_t ** | rb, |
const size_t | size | ||
) |
Allocates a ring buffer.
Allocates and initializes memory to store a ring buffer. This functions allocates memory for the ring buffer structure as well as memory for the ring buffer itself. This function allocates memory from the heap, if a ring buffer structure is on the stack, it can be initialized using function amxc_rbuffer_init
The size of the ring buffer is not fixed and can be changed with the functions amxc_rbuffer_grow or amxc_rbuffer_shrink
The size of the ring buffer is expressed in number of bytes that can be stored in the ring buffer.
rb | a pointer to the location where the pointer to the new ring buffer structure can be stored |
size | the size of the ring buffer in number of bytes |
Definition at line 79 of file amxc_rbuffer.c.
ssize_t amxc_rbuffer_read | ( | amxc_rbuffer_t *const | rb, |
char *const | buf, | ||
size_t | count | ||
) |
Reads a number of bytes from the ring buffer.
Copies bytes from the ring buffer, starting from the current read position, into the provided buffer to a maximum number of bytes specified. When less bytes then the specified count are copied in the provided buffer, no more data is available in the ring buffer.
rb | a pointer to the ring buffer structure |
buf | a pointer to a buffer where the data can be copied in. |
count | the maximum number of bytes that can be copied |
Definition at line 250 of file amxc_rbuffer.c.
int amxc_rbuffer_shrink | ( | amxc_rbuffer_t *const | rb, |
const size_t | size | ||
) |
Shrinks the ring buffer.
Shrinks the ring buffer by the given number of bytes. The memory is freed.
rb | a pointer to the ring buffer structure |
size | the number of bytes the ring buffer has to shrink |
Definition at line 190 of file amxc_rbuffer.c.
size_t amxc_rbuffer_size | ( | const amxc_rbuffer_t *const | rb | ) |
Get the size of the data stored in the ring buffer.
rb | a pointer to the ring buffer structure |
Definition at line 327 of file amxc_rbuffer.c.
ssize_t amxc_rbuffer_write | ( | amxc_rbuffer_t *const | rb, |
const char *const | buf, | ||
const size_t | count | ||
) |
Writes a number of bytes to the ring buffer.
Copies the specified number of bytes to the ring buffer, starting from the current write position, from the provided buffer. The ring buffer grows when there is not enough space left in the ring buffer.
rb | a pointer to the ring buffer structure |
buf | a pointer to a buffer that contains the data that must be put in the ring buffer. |
count | the number of bytes that need to be copied in the ring buffer |
Definition at line 292 of file amxc_rbuffer.c.