|
| VL_API vl_buffer * | vlBufferNewExt (vl_memsize_t size, vl_uint16_t align) |
| | Allocates a new buffer, and initializes it with the specified capacity. The buffer must be deleted with vlBufferDelete(...) when it is no longer being used to avoid leaking memory.
|
| |
| VL_API void | vlBufferInitExt (vl_buffer *buffer, vl_memsize_t size, vl_uint16_t align) |
| | Initializes a buffer instance with specific size and alignment.
|
| |
| VL_API void | vlBufferReset (vl_buffer *buffer, vl_memsize_t newCapacity) |
| | Resets the state of the specified buffer, setting the offset integer to zero and the computed size to zero. This will re-allocate the buffer to hold the specified capacity.
|
| |
| VL_API void | vlBufferClear (vl_buffer *buffer) |
| | Sets the entirety of the buffer to zero. Also resets offset and computed size to zero.
|
| |
| VL_API void | vlBufferShrinkToFit (vl_buffer *buffer) |
| | Resizes the specified buffer to hold a capacity equal to the current computed size.
|
| |
| VL_API vl_buffer * | vlBufferClone (const vl_buffer *src, vl_buffer *dest) |
| | Clones the source buffer to the destination buffer.
|
| |
| VL_API 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_API 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, doubling capacity iteratively until it fits. The buffer offset will be incremented by the total number of bytes written.
|
| |
| VL_API 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.
|
| |
| VL_API void | vlBufferFree (vl_buffer *buffer) |
| | Frees the internal data of the specified buffer.
|
| |
| VL_API void | vlBufferDelete (vl_buffer *buffer) |
| | Deletes the specified buffer and its internal data.
|
| |
| VL_API vl_buffer * vlBufferClone |
( |
const vl_buffer * |
src, |
|
|
vl_buffer * |
dest |
|
) |
| |
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 (offset, size) 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.
Contract
- Ownership: If
dest is NULL, the caller owns the returned vl_buffer. If dest is provided, ownership remains with the caller.
- Lifetime: The
dest buffer is valid until vlBufferDelete (if newly allocated) or vlBufferFree.
- Thread Safety: Not thread-safe.
- Nullability:
src must not be NULL. dest can be NULL.
- Error Conditions: Returns
NULL if new buffer allocation fails when dest is NULL.
- Undefined Behavior: Passing an uninitialized buffer.
- Memory Allocation Expectations: May allocate a new
vl_buffer struct and/or a new data block via vlMemAllocAligned or vlMemRealloc.
- Return-value Semantics: Returns the pointer to the cloned buffer (
dest or the new instance).
- See also
- vlBufferNew
-
vlBufferCopy
- Parameters
-
| src | source buffer pointer |
| dest | destination buffer pointer, or NULL. |
- Complexity O(n) where n = buffer capacity.
- Returns
- 'dest' buffer, or buffer created via vlBufferNew.
| VL_API 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, doubling capacity iteratively until it fits. The buffer offset will be incremented by the total number of bytes written.
Providing a NULL source pointer will reserve space in the buffer without copying any data. Existing data within the reserved range is not modified, and can be directly written to.
Contract
- Ownership: Ownership of
buffer and src is unchanged.
- Lifetime: Both must be valid during the call.
- Thread Safety: Not thread-safe.
- Nullability:
buffer must not be NULL. src can be NULL to reserve space.
- Error Conditions: If internal reallocation fails,
buffer->data may become invalid or NULL.
- Undefined Behavior: Passing an uninitialized buffer.
- Memory Allocation Expectations: Automatically grows the buffer capacity (doubling) if the write exceeds current capacity.
- Return-value Semantics: Returns the offset at which the write started.
- Complexity O(n) where n = param size
- Parameters
-
| buffer | struct pointer |
| size | total number of bytes to write |
| src | pointer to the memory that will be copied from |
- Returns
- the offset at which the bytes were written into the buffer.