|
Veritable Lasagna
An Allocator & Data Structure Library for C.
|
#include "vl_buffer.h"
Include dependency graph for vl_stack.h:
This graph shows which files directly or indirectly include this file:Go to the source code of this file.
Data Structures | |
| struct | vl_stack |
| A virtual stack allocator. More... | |
Macros | |
| #define | vlStackSize(stackPtr) ((stackPtr)->depth) |
| Returns the size of the specified stack. | |
| #define | vlStackEmpty(stackPtr) ((stackPtr)->depth == 0) |
| Returns a boolean indicating if the specified stack is empty. | |
Functions | |
| VL_API void | vlStackInit (vl_stack *stack) |
| Initializes the underlying memory of an existing vl_stack pointer. The stack allocator should be freed with vlStackFree. | |
| VL_API void | vlStackFree (vl_stack *stack) |
| Frees the specified stack instance's internal allocation. | |
| VL_API vl_stack * | vlStackNew (void) |
| Allocates on the heap, initializes, and returns a new stack allocator instance. | |
| VL_API void | vlStackDelete (vl_stack *stack) |
| Deletes the specified stack and its internal buffer. | |
| VL_API void | vlStackReset (vl_stack *stack) |
| Resets the specified stack allocator, allowing it to be used as if it had just been initialized. | |
| 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. | |
| 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. | |
| VL_API vl_transient * | vlStackPeek (vl_stack *stack) |
| Returns a pointer to the top level of the stack. | |
| VL_API vl_memsize_t | vlStackPeekSize (vl_stack *stack) |
| Returns the size of the top level of the stack, in bytes. | |
| VL_API vl_transient * | vlStackSample (vl_stack *stack, vl_stack_offset offset) |
| Samples the stack at the specified offset. | |
| VL_API vl_memsize_t | vlStackSampleSize (vl_stack *stack, vl_stack_offset offset) |
| Samples the size of the stack level at the specified offset. | |
| VL_API void | vlStackPop (vl_stack *stack) |
| Pops the top level of the stack, allowing it to be overwritten in the future. | |
| struct vl_stack |
A virtual stack allocator.
The vl_stack structure represents a stack allocator data structure. It is built on top of the vl_buffer structure, which manages dynamic resizing.
This structure might not be be quite as easy to use as you might anticipate, due to the necessity to explicitly define the size of each level of the stack in bytes. This should be fairly easy to define using sizeof() or simply computing the size.
This structure also allows for sampling properties low in the stack, if an appropriate offset is given. Many stack data structure implementations prohibit this, however there are notable applications for this kind of use.
Collaboration diagram for vl_stack:| Data Fields | ||
|---|---|---|
| vl_buffer | buffer | |
| vl_dsidx_t | depth | |
| vl_uintptr_t | headOffset | |
| #define vlStackEmpty | ( | stackPtr | ) | ((stackPtr)->depth == 0) |
Returns a boolean indicating if the specified stack is empty.
| stackPtr | pointer |
| #define vlStackSize | ( | stackPtr | ) | ((stackPtr)->depth) |
Returns the size of the specified stack.
| stackPtr | pointer |
| VL_API void vlStackDelete | ( | vl_stack * | stack | ) |
Deletes the specified stack and its internal buffer.
This stack allocator should have been initialized via vlStackNew.
vl_stack struct.stack is NULL.| stack | pointer |
Here is the call graph for this function:| VL_API void vlStackFree | ( | vl_stack * | stack | ) |
Frees the specified stack instance's internal allocation.
Frees the internal buffer used by the stack allocator. This stack allocator should first be initialized via vlStackInit.
stack struct itself.stack must not be NULL.| stack | pointer |
Here is the call graph for this function:
Here is the caller graph for this function:| VL_API void vlStackInit | ( | vl_stack * | stack | ) |
Initializes the underlying memory of an existing vl_stack pointer. The stack allocator should be freed with vlStackFree.
stack struct. The function initializes the internal buffer.vlStackFree or vlStackDelete.stack must not be NULL.vlStackFree (causes memory leak).vl_buffer which allocates an initial data block.| stack | stack pointer |
Here is the caller graph for this function:| VL_API vl_stack * vlStackNew | ( | void | ) |
Allocates on the heap, initializes, and returns a new stack allocator instance.
vl_stack pointer and is responsible for calling vlStackDelete.vlStackDelete.NULL if heap allocation for the stack struct fails.NULL on allocation failure.vl_stack struct and its internal buffer.NULL.
Here is the call graph for this function:| VL_API vl_transient * vlStackPeek | ( | vl_stack * | stack | ) |
Returns a pointer to the top level of the stack.
Results in undefined behavior if the stack is empty.
stack must not be NULL.| stack | pointer |
Here is the caller graph for this function:| VL_API vl_memsize_t vlStackPeekSize | ( | vl_stack * | stack | ) |
Returns the size of the top level of the stack, in bytes.
Results in undefined behavior if the stack is empty.
stack must not be NULL.| stack | pointer |
| VL_API void vlStackPop | ( | vl_stack * | stack | ) |
Pops the top level of the stack, allowing it to be overwritten in the future.
stack must not be NULL.| stack |
Here is the caller graph for this function:| 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.
This may force the underlying buffer to grow in size, which may invalidate the result of all prior calls to vlStackPeek and vlStackSample.
stack must not be NULL.vl_buffer.vl_stack_offset of the newly pushed block.| stack | pointer |
| size | total bytes in the reserved block |
Here is the call graph for this function:
Here is the caller graph for this function:| 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.
This may force the underlying buffer to grow in size, which may invalidate the result of all prior calls to vlStackPeek and vlStackSample.
vlStackPush.stack must not be NULL. data should not be NULL.vl_buffer.vl_stack_offset of the newly pushed block.| stack | pointer |
| data | pointer to the element data |
| size | total bytes in the reserved block |
Here is the call graph for this function:| VL_API void vlStackReset | ( | vl_stack * | stack | ) |
Resets the specified stack allocator, allowing it to be used as if it had just been initialized.
This does NOT modify any of the information in the underlying buffer, but rather resets some variables used for book-keeping.
stack must not be NULL.| stack | pointer |
Here is the caller graph for this function:| VL_API vl_transient * vlStackSample | ( | vl_stack * | stack, |
| vl_stack_offset | offset | ||
| ) |
Samples the stack at the specified offset.
Results in undefined behavior if the offset is invalid.
stack must not be NULL.| stack | pointer |
| offset | level of the stack to sample |
Here is the caller graph for this function:| VL_API vl_memsize_t vlStackSampleSize | ( | vl_stack * | stack, |
| vl_stack_offset | offset | ||
| ) |
Samples the size of the stack level at the specified offset.
Results in undefined behavior if the specified offset is invalid.
stack must not be NULL.| stack | pointer |
| offset | level of the stack |