Veritable Lasagna
An Allocator & Data Structure Library for C.
Loading...
Searching...
No Matches
vl_stack.h
Go to the documentation of this file.
1
14#ifndef VL_STACK_H
15#define VL_STACK_H
16
17#include "vl_buffer.h"
18
19typedef vl_dsoffs_t vl_stack_offset;
20
37typedef struct
38{
41 vl_buffer buffer;
42} vl_stack;
43
63VL_API void vlStackInit(vl_stack* stack);
64
85VL_API void vlStackFree(vl_stack* stack);
86
104VL_API vl_stack* vlStackNew(void);
105
125VL_API void vlStackDelete(vl_stack* stack);
126
147VL_API void vlStackReset(vl_stack* stack);
148
177VL_API vl_stack_offset vlStackPush(vl_stack* stack, vl_memsize_t size);
178
207VL_API vl_stack_offset vlStackPushValue(vl_stack* stack, const void* data, vl_memsize_t size);
208
228VL_API vl_transient* vlStackPeek(vl_stack* stack);
229
249VL_API vl_memsize_t vlStackPeekSize(vl_stack* stack);
250
271VL_API vl_transient* vlStackSample(vl_stack* stack, vl_stack_offset offset);
272
273#ifndef vlStackSize
274
281#define vlStackSize(stackPtr) ((stackPtr)->depth)
282#endif
283
284#ifndef vlStackEmpty
291#define vlStackEmpty(stackPtr) ((stackPtr)->depth == 0)
292#endif
293
314VL_API vl_memsize_t vlStackSampleSize(vl_stack* stack, vl_stack_offset offset);
315
333VL_API void vlStackPop(vl_stack* stack);
334
335#endif // VL_STACK_H
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_STRUCTURE_INDEX_T vl_dsidx_t
Index type for data structures.
Definition vl_numtypes.h:75
VL_STRUCTURE_OFFSET_T vl_dsoffs_t
Byte offset type for data structures.
Definition vl_numtypes.h:70
VL_API void vlStackDelete(vl_stack *stack)
Deletes the specified stack and its internal buffer.
Definition vl_stack.c:36
VL_API vl_stack_offset vlStackPushValue(vl_stack *stack, const void *data, vl_memsize_t size)
Reserves and assigns a new block of memory at the top of the stack, returning its offset.
Definition vl_stack.c:63
VL_API vl_transient * vlStackSample(vl_stack *stack, vl_stack_offset offset)
Samples the stack at the specified offset.
Definition vl_stack.c:70
VL_API vl_memsize_t vlStackPeekSize(vl_stack *stack)
Returns the size of the top level of the stack, in bytes.
Definition vl_stack.c:86
VL_API vl_stack_offset vlStackPush(vl_stack *stack, vl_memsize_t size)
Reserves a new block of memory at the top of the stack, returning its offset.
Definition vl_stack.c:49
VL_API vl_stack * vlStackNew(void)
Allocates on the heap, initializes, and returns a new stack allocator instance.
Definition vl_stack.c:29
vl_uintptr_t headOffset
Definition vl_stack.h:40
VL_API void vlStackFree(vl_stack *stack)
Frees the specified stack instance's internal allocation.
Definition vl_stack.c:27
vl_buffer buffer
Definition vl_stack.h:41
VL_API void vlStackPop(vl_stack *stack)
Pops the top level of the stack, allowing it to be overwritten in the future.
Definition vl_stack.c:92
VL_API void vlStackInit(vl_stack *stack)
Initializes the underlying memory of an existing vl_stack pointer. The stack allocator should be free...
Definition vl_stack.c:16
VL_API void vlStackReset(vl_stack *stack)
Resets the specified stack allocator, allowing it to be used as if it had just been initialized.
Definition vl_stack.c:42
vl_dsidx_t depth
Definition vl_stack.h:39
VL_API vl_memsize_t vlStackSampleSize(vl_stack *stack, vl_stack_offset offset)
Samples the size of the stack level at the specified offset.
Definition vl_stack.c:75
VL_API vl_transient * vlStackPeek(vl_stack *stack)
Returns a pointer to the top level of the stack.
Definition vl_stack.c:81
A virtual stack allocator.
Definition vl_stack.h:38