Veritable Lasagna
An Allocator & Data Structure Library for C.
Loading...
Searching...
No Matches
vl_buffer.h
Go to the documentation of this file.
1
14#ifndef VL_BUFFER_H
15#define VL_BUFFER_H
16
17#include "vl_memory.h"
18#include "vl_numtypes.h"
19
33typedef struct
34{
39 vl_memsize_t size;
40
44 vl_dsoffs_t offset;
45
49 vl_memory* data;
50} vl_buffer;
51
73VL_API vl_buffer* vlBufferNewExt(vl_memsize_t size, vl_uint16_t align);
74
82static inline vl_buffer* vlBufferNew(void) { return vlBufferNewExt(VL_DEFAULT_MEMORY_SIZE, VL_DEFAULT_MEMORY_ALIGN); }
83
105VL_API void vlBufferInitExt(vl_buffer* buffer, vl_memsize_t size, vl_uint16_t align);
106
119static inline void vlBufferInit(vl_buffer* buffer)
120{
122}
123
142VL_API void vlBufferReset(vl_buffer* buffer, vl_memsize_t newCapacity);
143
161VL_API void vlBufferClear(vl_buffer* buffer);
162
180VL_API void vlBufferShrinkToFit(vl_buffer* buffer);
181
216VL_API vl_buffer* vlBufferClone(const vl_buffer* src, vl_buffer* dest);
217
243VL_API vl_memsize_t vlBufferCopy(vl_buffer* src, vl_buffer* dest, vl_memsize_t len);
244
272VL_API vl_memsize_t vlBufferWrite(vl_buffer* buffer, vl_memsize_t size, const void* src);
273
297VL_API vl_memsize_t vlBufferRead(vl_buffer* buffer, vl_memsize_t size, void* dest);
298
317static inline void vlBufferSeek(vl_buffer* buffer, vl_uintptr_t offset) { buffer->offset = offset; }
318
338static inline void vlBufferSeekRelative(vl_buffer* buffer, vl_intptr_t offset) { buffer->offset += offset; }
339
358static inline void vlBufferSeekBegin(vl_buffer* buffer) { buffer->offset = 0; }
359
379static inline void vlBufferSeekEnd(vl_buffer* buffer) { buffer->offset = buffer->size; }
380
399static inline vl_transient* vlBufferBegin(vl_buffer* buffer) { return buffer->data; }
400
418static inline vl_transient* vlBufferEnd(vl_buffer* buffer) { return buffer->data + buffer->size; }
419
442VL_API void vlBufferFree(vl_buffer* buffer);
443
466VL_API void vlBufferDelete(vl_buffer* buffer);
467
468#endif // VL_BUFFER_H
VL_API void vlBufferClear(vl_buffer *buffer)
Sets the entirety of the buffer to zero. Also resets offset and computed size to zero.
Definition vl_buffer.c:33
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...
Definition vl_buffer.c:26
VL_API void vlBufferInitExt(vl_buffer *buffer, vl_memsize_t size, vl_uint16_t align)
Initializes a buffer instance with specific size and alignment.
Definition vl_buffer.c:16
VL_API void vlBufferDelete(vl_buffer *buffer)
Deletes the specified buffer and its internal data.
Definition vl_buffer.c:108
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 curre...
Definition vl_buffer.c:80
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 spe...
Definition vl_buffer.c:98
VL_API void vlBufferShrinkToFit(vl_buffer *buffer)
Resizes the specified buffer to hold a capacity equal to the current computed size.
Definition vl_buffer.c:40
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.
Definition vl_buffer.c:72
VL_API vl_buffer * vlBufferClone(const vl_buffer *src, vl_buffer *dest)
Clones the source buffer to the destination buffer.
Definition vl_buffer.c:46
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 wi...
Definition vl_buffer.c:6
VL_API void vlBufferFree(vl_buffer *buffer)
Frees the internal data of the specified buffer.
Definition vl_buffer.c:114
#define VL_DEFAULT_MEMORY_ALIGN
Default memory alignment. Defaults to maximum system word size.
Definition vl_memory.h:60
#define VL_DEFAULT_MEMORY_SIZE
Default 1kb allocation size.
Definition vl_memory.h:46
VL_MEMORY_T vl_memory
Definition vl_memory.h:108
VL_MEMORY_T vl_transient
Definition vl_memory.h:118
VL_UPTR_T vl_uintptr_t
Unsigned integer type suitable for expressing memory addresses.
Definition vl_numtypes.h:163
VL_IPTR_T vl_intptr_t
Signed integer type suitable for expressing memory addresses.
Definition vl_numtypes.h:168
VL_STRUCTURE_OFFSET_T vl_dsoffs_t
Byte offset type for data structures.
Definition vl_numtypes.h:70