Veritable Lasagna
An Allocator & Data Structure Library for C.
|
Go to the source code of this file.
Data Structures | |
struct | vl_buffer |
A multi-purpose byte buffer. More... | |
Macros | |
#define | vlBufferInit(bufferPtr) vlBufferInitSz(bufferPtr, VL_DEFAULT_MEMORY_SIZE) |
Initializes a buffer instance for the first time. This will create the initial allocation for the default capacity. | |
Functions | |
vl_buffer * | vlBufferNew (void) |
Allocates a new buffer, and initializes it with the default capacity. The buffer must be deleted with vlBufferDelete(...) when it is no longer being used to avoid leaking memory. | |
vl_buffer * | vlBufferNewSz (vl_memsize_t initialCapacity) |
Allocates a new buffer, and initializes it with a capacity of N bytes. The buffer must be deleted with vlBufferDelete(...) when it is no longer being used to avoid leaking memory. | |
void | vlBufferInitSz (vl_buffer *buffer, vl_memsize_t initialCapacity) |
Initializes a buffer instance for the first time. This will create the initial allocation for the specified capacity. | |
void | vlBufferReset (vl_buffer *buffer) |
Resets the state of the specified buffer, setting the offset integer to zero. This will re-allocate the buffer to hold the default capacity. | |
void | vlBufferResetSz (vl_buffer *buffer, vl_memsize_t newCapacity) |
Resets the state of the specified buffer, setting the offset integer to zero. This will re-allocate the buffer to hold the specified capacity. | |
void | vlBufferClear (vl_buffer *buffer) |
Sets the entirety of the buffer to zero. Also resets offset and computed size. | |
void | vlBufferShrinkToFit (vl_buffer *buffer) |
Resizes the specified buffer to hold a capacity equal to the current size. | |
vl_buffer * | vlBufferClone (const vl_buffer *src, vl_buffer *dest) |
Clones the source buffer to the destination buffer. | |
vl_memsize_t | vlBufferCopy (vl_buffer *src, vl_buffer *dest, vl_memsize_t len) |
Copies a series of bytes from one buffer to another. | |
vl_memsize_t | vlBufferWrite (vl_buffer *buffer, vl_memsize_t size, const void *src) |
Performs a copy from the specified source pointer into the buffer. The bytes are written at the current offset integer belonging to the buffer state. This function will resize the buffer when necessary. The buffer offset will be incremented by the total number of bytes written. | |
vl_memsize_t | vlBufferRead (vl_buffer *buffer, vl_memsize_t size, void *dest) |
Copies bytes from the buffer to the specified destination. Performs a copy from the buffer to the specified destination pointer. This will increment the buffer offset. | |
void | vlBufferSeek (vl_buffer *buffer, vl_uintptr_t offset) |
Sets the buffer offset relative to the beginning of the allocation. | |
void | vlBufferSeekRelative (vl_buffer *buffer, vl_intptr_t offset) |
Seeks the internal offset relative to the current offset. Adds the specified offset to the offset integer belonging to the buffer state. | |
void | vlBufferSeekBegin (vl_buffer *buffer) |
Seeks the internal offset to the beginning of the buffer. Moves the offset integer belonging to the buffer state to the beginning of the allocation (e.g, zero) | |
void | vlBufferSeekEnd (vl_buffer *buffer) |
Seeks the internal offset to the end of the buffer. Moves the offset integer belonging to the buffer state to the end of the allocation (e.g, the buffer size) | |
vl_transient * | vlBufferBegin (vl_buffer *buffer) |
Returns a pointer to the beginning of the buffer allocation. | |
vl_transient * | vlBufferEnd (vl_buffer *buffer) |
Returns a pointer to the end of the buffer allocation. | |
void | vlBufferFree (vl_buffer *buffer) |
Frees the specified buffer. | |
void | vlBufferDelete (vl_buffer *buffer) |
Deletes the specified buffer. | |
struct vl_buffer |
A multi-purpose byte buffer.
Buffers are the most basic data structure used by the VL library (aside from simple blocks of memory) Every other data structure uses a vl_buffer somewhere in their implementation. Most comparable to a standard Vector or ArrayList, the buffer is capable of resizing itself according to write operations by doubling its size for new elements.
Buffers do offer stateful functionality used to treat them as streams (e.g, seeking). Unless otherwise specified, the default initial capacity is equal to VL_DEFAULT_MEMORY_SIZE.
Data Fields | ||
---|---|---|
vl_memory * | data | Actual allocation managed by the buffer. |
vl_dsoffs_t | offset | Read-write offset of the buffer. |
vl_memsize_t | size | Virtual size of the buffer. Actual capacity of the allocation is always equal to or larger. |
#define vlBufferInit | ( | bufferPtr | ) | vlBufferInitSz(bufferPtr, VL_DEFAULT_MEMORY_SIZE) |
Initializes a buffer instance for the first time. This will create the initial allocation for the default capacity.
This buffer should be deleted via vlBufferFree.
buffer | struct pointer |
vl_transient * vlBufferBegin | ( | vl_buffer * | buffer | ) |
Returns a pointer to the beginning of the buffer allocation.
buffer | struct pointer |
void vlBufferClear | ( | vl_buffer * | buffer | ) |
Sets the entirety of the buffer to zero. Also resets offset and computed size.
buffer | struct pointer |
Clones the source buffer to the destination buffer.
This is a 'complete' clone of the entirety of the buffer, and thus includes all related state alongside a copy of the underlying block of memory.
When simply copying data from one buffer to another, consider the more stateful vlBufferCopy.
The 'src' buffer must be non-null and point to an initialized buffer. The 'dest' buffer must be either null, or a pointer to an initialized buffer.
If the 'dest' buffer is null, a new instance is created via vlBufferNew. It must later be disposed using vlBufferDelete if this is the case.
src | source buffer pointer |
dest | destination buffer pointer, or NULL. |
vl_memsize_t vlBufferCopy | ( | vl_buffer * | src, |
vl_buffer * | dest, | ||
vl_memsize_t | len ) |
Copies a series of bytes from one buffer to another.
The read from the src buffer and the write to the dest buffer are relative to their current respective offsets.
If there are less bytes available in the source buffer than those specified by len, the copy is performed up to the end of the source.
src | source buffer pointer |
dest | destination buffer pointer |
len | total number of bytes to attempt to copy. |
void vlBufferDelete | ( | vl_buffer * | buffer | ) |
Deletes the specified buffer.
The buffer should have been initialized via vlBufferNew(Sz) or vlBufferClone.
buffer | struct pointer |
vl_transient * vlBufferEnd | ( | vl_buffer * | buffer | ) |
Returns a pointer to the end of the buffer allocation.
buffer | struct pointer |
void vlBufferFree | ( | vl_buffer * | buffer | ) |
Frees the specified buffer.
The buffer should have been initialized via vlBufferInit(Sz).
buffer | struct pointer |
void vlBufferInitSz | ( | vl_buffer * | buffer, |
vl_memsize_t | initialCapacity ) |
Initializes a buffer instance for the first time. This will create the initial allocation for the specified capacity.
This buffer should be deleted via vlBufferFree.
buffer | struct pointer |
initialCapacity | total number of initial bytes the buffer will have the capacity to hold. |
vl_buffer * vlBufferNew | ( | void | ) |
Allocates a new buffer, and initializes it with the default capacity. The buffer must be deleted with vlBufferDelete(...) when it is no longer being used to avoid leaking memory.
vl_buffer * vlBufferNewSz | ( | vl_memsize_t | initialCapacity | ) |
Allocates a new buffer, and initializes it with a capacity of N bytes. The buffer must be deleted with vlBufferDelete(...) when it is no longer being used to avoid leaking memory.
initialCapacity | initial capacity N |
vl_memsize_t vlBufferRead | ( | vl_buffer * | buffer, |
vl_memsize_t | size, | ||
void * | dest ) |
Copies bytes from the buffer to the specified destination. Performs a copy from the buffer to the specified destination pointer. This will increment the buffer offset.
buffer | struct pointer |
size | total number of bytes to attempt to copy |
dest | pointer to the memory that will be copied to |
void vlBufferReset | ( | vl_buffer * | buffer | ) |
Resets the state of the specified buffer, setting the offset integer to zero. This will re-allocate the buffer to hold the default capacity.
buffer | struct pointer |
void vlBufferResetSz | ( | vl_buffer * | buffer, |
vl_memsize_t | newCapacity ) |
Resets the state of the specified buffer, setting the offset integer to zero. This will re-allocate the buffer to hold the specified capacity.
buffer | struct pointer |
newCapacity | new capacity, in bytes |
void vlBufferSeek | ( | vl_buffer * | buffer, |
vl_uintptr_t | offset ) |
Sets the buffer offset relative to the beginning of the allocation.
buffer | struct pointer |
offset | total number of bytes, positive, to seek forward. |
void vlBufferSeekBegin | ( | vl_buffer * | buffer | ) |
Seeks the internal offset to the beginning of the buffer. Moves the offset integer belonging to the buffer state to the beginning of the allocation (e.g, zero)
buffer | struct pointer |
void vlBufferSeekEnd | ( | vl_buffer * | buffer | ) |
Seeks the internal offset to the end of the buffer. Moves the offset integer belonging to the buffer state to the end of the allocation (e.g, the buffer size)
buffer | struct pointer |
void vlBufferSeekRelative | ( | vl_buffer * | buffer, |
vl_intptr_t | offset ) |
Seeks the internal offset relative to the current offset. Adds the specified offset to the offset integer belonging to the buffer state.
buffer | struct pointer |
offset | total number of bytes, positive or negative, to seek. |
void vlBufferShrinkToFit | ( | vl_buffer * | buffer | ) |
Resizes the specified buffer to hold a capacity equal to the current size.
buffer | struct pointer |
vl_memsize_t vlBufferWrite | ( | vl_buffer * | buffer, |
vl_memsize_t | size, | ||
const void * | src ) |
Performs a copy from the specified source pointer into the buffer. The bytes are written at the current offset integer belonging to the buffer state. This function will resize the buffer when necessary. The buffer offset will be incremented by the total number of bytes written.
buffer | struct pointer |
size | total number of bytes to write |
src | pointer to the memory that will be copied from |