|
Veritable Lasagna
An Allocator & Data Structure Library for C.
|
#include "vl_set.h"
Include dependency graph for vl_arena.h:
This graph shows which files directly or indirectly include this file:Go to the source code of this file.
Data Structures | |
| struct | vl_arena |
| An arena allocator for efficient memory management. More... | |
Macros | |
| #define | VL_ARENA_NULL 0 |
| An explicit NULL integer constant that indicates a bad location in an arena. | |
Functions | |
| VL_API void | vlArenaInit (vl_arena *arena, vl_memsize_t initialSize) |
| Initializes the vl_arena structure with the given initial size. | |
| VL_API void | vlArenaFree (vl_arena *arena) |
| Frees memory allocated by an arena instance. | |
| VL_API vl_arena * | vlArenaNew (vl_memsize_t initialSize) |
| Creates a new arena with the specified initial size. | |
| VL_API void | vlArenaDelete (vl_arena *arena) |
| Deletes the given VL arena, freeing all allocated memory and the arena struct itself. | |
| VL_API void | vlArenaClear (vl_arena *arena) |
| Clears all the allocations in the given arena. | |
| VL_API vl_arena * | vlArenaClone (const vl_arena *src, vl_arena *dest) |
| Clones the specified arena to another. | |
| VL_API void | vlArenaReserve (vl_arena *arena, vl_memsize_t numBytes) |
| Reserves storage in the underlying allocation of the given arena. | |
| VL_API vl_arena_ptr | vlArenaMemAlloc (vl_arena *arena, vl_memsize_t size) |
| Take memory from the given arena. | |
| VL_API vl_arena_ptr | vlArenaMemRealloc (vl_arena *arena, vl_arena_ptr ptr, vl_memsize_t size) |
| Reallocates memory for the given pointer in the given arena. | |
| VL_API void | vlArenaMemFree (vl_arena *arena, vl_arena_ptr ptr) |
| Frees a memory block allocated in a vl_arena. | |
| VL_API vl_arena_ptr | vlArenaMemPrepend (vl_arena *arena, vl_arena_ptr dst, const void *src, vl_memsize_t length) |
| Copies a block of memory to the beginning of the specified arena allocation. | |
| VL_API vl_arena_ptr | vlArenaMemAppend (vl_arena *arena, vl_arena_ptr dst, const void *src, vl_memsize_t length) |
| Copies a block of memory to the end of the specified arena allocation. | |
| VL_API vl_transient * | vlArenaMemSample (vl_arena *arena, vl_arena_ptr ptr) |
| Sampling function that calculates a transient pointer into the specified arena. | |
| VL_API vl_memsize_t | vlArenaMemSize (vl_arena *arena, vl_arena_ptr ptr) |
| Get the size of a memory block allocated in a VL arena. | |
| VL_API vl_memsize_t | vlArenaTotalCapacity (vl_arena *arena) |
| Get the total capacity of the arena. | |
| VL_API vl_memsize_t | vlArenaTotalFree (vl_arena *arena) |
| Get the total amount of free memory in the arena. | |
| struct vl_arena |
An arena allocator for efficient memory management.
The Arena allocator provides a memory management strategy that efficiently handles multiple allocations from a single large memory block. It implements a sophisticated allocation strategy with the following key features:
Collaboration diagram for vl_arena:| Data Fields | ||
|---|---|---|
| vl_memory * | data | |
| vl_set | freeSet | |
| #define VL_ARENA_NULL 0 |
An explicit NULL integer constant that indicates a bad location in an arena.
Using a regular 0 = NULL here works, as no valid allocation will have that offset. This is due to the implicit metadata prepended to each allocation.
| VL_API void vlArenaClear | ( | vl_arena * | arena | ) |
Clears all the allocations in the given arena.
This function removes all the elements in the arena, making it empty. The memory allocated for the internal data block is not released, but all previous allocations are marked as free.
vl_arena_ptr handles and sampled pointers become invalid.arena must not be NULL.| arena | Pointer to the vl_arena structure. |
Here is the call graph for this function:
Here is the caller graph for this function:Clones the specified arena to another.
Clones the entirety of the src arena to the dest arena, including all allocated blocks and free set state.
The 'src' arena pointer must be non-null and initialized. The 'dest' arena pointer may be null, but if it is not null it must be initialized.
If the 'dest' arena pointer is null, a new arena is created via vlArenaNew.
dest is NULL, the caller owns the returned vl_arena pointer. If dest is provided, ownership remains with the caller.src must not be NULL. dest can be NULL.NULL on allocation failure.vl_arena struct (if dest is NULL) and a new data block.dest or a new instance), or NULL on failure.| src | pointer |
| dest | pointer |
Here is the call graph for this function:
Here is the caller graph for this function:| VL_API void vlArenaDelete | ( | vl_arena * | arena | ) |
Deletes the given VL arena, freeing all allocated memory and the arena struct itself.
vl_arena struct.arena can be NULL (safely handled by free).vlMemFree and the struct via free.| arena | Pointer to the VL arena to be deleted. |
Here is the call graph for this function:| VL_API void vlArenaFree | ( | vl_arena * | arena | ) |
Frees memory allocated by an arena instance.
De-initializes the arena by freeing its underlying memory block and the free set.
arena struct itself.vl_arena_ptr handles and sampled pointers become invalid.arena must not be NULL.vlMemFree.| arena | Pointer to the arena instance to be freed. |
Here is the call graph for this function:
Here is the caller graph for this function:| VL_API void vlArenaInit | ( | vl_arena * | arena, |
| vl_memsize_t | initialSize | ||
| ) |
Initializes the vl_arena structure with the given initial size.
This function initializes a vl_arena structure with the specified initial size. The initial size determines the number of elements that the arena can hold initially.
arena struct. The function initializes the internal memory block and free set.vlArenaFree or vlArenaDelete.arena must not be NULL.vlMemAlloc fails for the initial data block, arena->data will be NULL.initialSize bytes via vlMemAlloc.| arena | The vl_arena structure to be initialized. |
| initialSize | The initial size of the arena. |
Here is the call graph for this function:
Here is the caller graph for this function:| VL_API vl_arena_ptr vlArenaMemAlloc | ( | vl_arena * | arena, |
| vl_memsize_t | size | ||
| ) |
Take memory from the given arena.
This function is used to allocate memory from the specified arena. Memory is allocated by finding a free block of memory of equal or greater size within the internally managed block of memory.
vl_arena_ptr handle.vlArenaMemFree, the arena is cleared, or the arena is destroyed.VL_ARENA_NULL if allocation fails.VL_ARENA_NULL if no block is large enough and internal expansion (doubling) fails.vl_arena_ptr handle to the allocated memory, or VL_ARENA_NULL on failure.| arena | A pointer to the arena from which memory will be allocated. |
| size | The size of the memory to be allocated in bytes. |
Here is the call graph for this function:
Here is the caller graph for this function:| VL_API vl_arena_ptr vlArenaMemAppend | ( | vl_arena * | arena, |
| vl_arena_ptr | dst, | ||
| const void * | src, | ||
| vl_memsize_t | length | ||
| ) |
Copies a block of memory to the end of the specified arena allocation.
This function handles the case wherein the specified source pointer resides within the arena.
vlArenaMemPrepend.vlArenaMemPrepend.VL_ARENA_NULL if reallocation fails.vlArenaMemPrepend.vlArenaMemRealloc.vl_arena_ptr handle.| arena | pointer |
| dst | arena pointer |
| src | memory to copy from |
| length | number of bytes from src |
Here is the call graph for this function:| VL_API void vlArenaMemFree | ( | vl_arena * | arena, |
| vl_arena_ptr | ptr | ||
| ) |
Frees a memory block allocated in a vl_arena.
This function frees the memory block referenced by the given pointer from the specified vl_arena. The memory block must have been previously allocated using the vlArenaMemAlloc() or vlArenaMemRealloc() functions.
vl_arena_ptr handle becomes invalid.ptr should not be VL_ARENA_NULL.| arena | The vl_arena structure representing the arena. |
| ptr | The pointer to the memory block to be freed. |
Here is the call graph for this function:
Here is the caller graph for this function:| VL_API vl_arena_ptr vlArenaMemPrepend | ( | vl_arena * | arena, |
| vl_arena_ptr | dst, | ||
| const void * | src, | ||
| vl_memsize_t | length | ||
| ) |
Copies a block of memory to the beginning of the specified arena allocation.
This function handles the case wherein the specified source pointer resides within the arena.
dst handle may be replaced by a new handle. Sampled pointers are invalidated.arena, dst, and src should not be NULL/VL_ARENA_NULL.VL_ARENA_NULL if reallocation fails.vlArenaMemRealloc.vl_arena_ptr handle to the modified allocation.| arena | pointer |
| dst | arena pointer |
| src | memory to copy from |
| length | number of bytes from src |
Here is the call graph for this function:| VL_API vl_arena_ptr vlArenaMemRealloc | ( | vl_arena * | arena, |
| vl_arena_ptr | ptr, | ||
| vl_memsize_t | size | ||
| ) |
Reallocates memory for the given pointer in the given arena.
This function reallocates memory for a previously allocated block of memory in the specified arena. If the reallocation is successful, the old block of memory will be freed and the new block will have a size specified by the 'size' parameter.
vl_arena_ptr handle may be invalidated and replaced by a new one. Sampled pointers are invalidated.VL_ARENA_NULL if reallocation fails.VL_ARENA_NULL on failure.vl_arena_ptr.vl_arena_ptr handle to the reallocated memory, or VL_ARENA_NULL.| arena | The arena to perform the reallocation on. |
| ptr | The pointer to the previously allocated block of memory. |
| size | The desired size of the newly reallocated block of memory. |
Here is the call graph for this function:
Here is the caller graph for this function:| VL_API vl_transient * vlArenaMemSample | ( | vl_arena * | arena, |
| vl_arena_ptr | ptr | ||
| ) |
Sampling function that calculates a transient pointer into the specified arena.
vlArenaMemAlloc, vlArenaReserve, vlArenaMemRealloc).NULL if arena->data is NULL.vl_arena_ptr.vl_transient* pointer to the memory location.| arena | The arena on which the operation is performed. |
| ptr | The arena pointer indicating the memory location on the arena. |
Here is the caller graph for this function:| VL_API vl_memsize_t vlArenaMemSize | ( | vl_arena * | arena, |
| vl_arena_ptr | ptr | ||
| ) |
Get the size of a memory block allocated in a VL arena.
This function returns the size of the memory block allocated at the specified pointer in a VL arena. The size is calculated based on the arena's metadata and may not represent the exact size of the data stored in the block.
arena and ptr must not be NULL/VL_ARENA_NULL.| arena | Pointer to the VL arena. |
| ptr | Pointer to the memory block. |
Here is the caller graph for this function:| VL_API vl_arena * vlArenaNew | ( | vl_memsize_t | initialSize | ) |
Creates a new arena with the specified initial size.
This function initializes a new arena with the specified initial size. The arena is used to dynamically allocate memory and manage it efficiently using a memory region structure.
vl_arena pointer and is responsible for calling vlArenaDelete.vlArenaDelete.NULL if heap allocation for the vl_arena struct fails.NULL on allocation failure.vl_arena struct and its initial data block.NULL.| initialSize | The initial size of the arena. |
Here is the call graph for this function:
Here is the caller graph for this function:| VL_API void vlArenaReserve | ( | vl_arena * | arena, |
| vl_memsize_t | numBytes | ||
| ) |
Reserves storage in the underlying allocation of the given arena.
This is done by doubling the size until the requested growth is met or exceeded. This function will always result in the reallocation of the underlying memory.
vl_arena_ptr handles remain stable, but all sampled standard pointers are invalidated.arena must not be NULL.vlMemRealloc fails, arena->data may become NULL.| arena | pointer |
| numBytes | total bytes to reserve |
Here is the call graph for this function:
Here is the caller graph for this function:| VL_API vl_memsize_t vlArenaTotalCapacity | ( | vl_arena * | arena | ) |
Get the total capacity of the arena.
This function returns the total capacity of the given arena, in bytes. The capacity represents the maximum number of elements that the arena can store without requiring reallocation.
arena must not be NULL.| arena | Pointer to the arena structure. |
Here is the call graph for this function:| VL_API vl_memsize_t vlArenaTotalFree | ( | vl_arena * | arena | ) |
Get the total amount of free memory in the arena.
This function returns the total amount of free memory in the specified arena by summing all blocks in the free set.
arena must not be NULL.| arena | The pointer to the arena structure. |
Here is the call graph for this function:
Here is the caller graph for this function: