|
CX Framework
Cross-platform C utility framework
|
Data Structures | |
| struct | BufferHeader |
Functions | |
| Buffer | bufCreate (size_t size) |
| Buffer | bufTryCreate (size_t size) |
| void | bufResize (Buffer *buf, size_t newsize) |
| bool | bufTryResize (Buffer *buf, size_t newsize) |
| void | bufDestroy (Buffer *buf) |
Simple dynamically-sized buffers with header metadata.
Buffers are heap-allocated structures that store arbitrary binary data along with size and length tracking. They support resizing and optional allocation.
Example:
| Buffer bufCreate | ( | size_t | size | ) |
Buffer bufCreate(size_t size)
Create a new buffer with the specified size.
| size | The size in bytes to allocate for the buffer |
| void bufDestroy | ( | Buffer * | buf | ) |
Destroy a buffer and free its memory.
Sets the buffer pointer to NULL after freeing.
| buf | Pointer to buffer pointer to destroy |
| void bufResize | ( | Buffer * | buf, |
| size_t | newsize | ||
| ) |
void bufResize(Buffer* buf, size_t newsize)
Resize an existing buffer to a new size.
If the buffer pointer is NULL, creates a new buffer with the specified size. If resizing smaller than current length, the length is truncated.
| buf | Pointer to buffer pointer to resize (may be NULL) |
| newsize | New size in bytes for the buffer |
| Buffer bufTryCreate | ( | size_t | size | ) |
Buffer bufTryCreate(size_t size)
Create a new buffer with optional allocation (may fail).
Uses optional allocation which will return NULL on out-of-memory instead of terminating the program. Useful for large allocations that may fail.
| size | The size in bytes to allocate for the buffer |
| bool bufTryResize | ( | Buffer * | buf, |
| size_t | newsize | ||
| ) |
bool bufTryResize(Buffer* buf, size_t newsize)
Resize an existing buffer with optional allocation (may fail).
Like bufResize() but uses optional allocation and returns false on failure instead of terminating the program.
| buf | Pointer to buffer pointer to resize (may be NULL) |
| newsize | New size in bytes for the buffer |