Veritable Lasagna
An Allocator & Data Structure Library for C.
|
Functions | |
void | vlArenaInit (vl_arena *arena, vl_memsize_t initialSize) |
Initializes the vl_arena structure with the given initial size. | |
void | vlArenaFree (vl_arena *arena) |
Frees memory allocated by an arena instance. | |
vl_arena * | vlArenaNew (vl_memsize_t initialSize) |
Creates a new arena with the specified initial size. | |
void | vlArenaDelete (vl_arena *arena) |
Deletes the given VL arena, freeing all allocated memory. | |
void | vlArenaClear (vl_arena *arena) |
Clears all the elements in the given arena. | |
vl_arena * | vlArenaClone (const vl_arena *src, vl_arena *dest) |
Clones the specified arena to another. | |
void | vlArenaReserve (vl_arena *arena, vl_memsize_t numBytes) |
Reserves storage in the underlying allocation of the given arena. | |
vl_arena_ptr | vlArenaMemAlloc (vl_arena *arena, vl_memsize_t size) |
Take memory from the given arena. | |
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. | |
void | vlArenaMemFree (vl_arena *arena, vl_arena_ptr ptr) |
Frees a memory block allocated in a vl_arena. | |
vl_arena_ptr | vlArenaMemPrepend (vl_arena *arena, vl_arena_ptr dstPtr, const void *src, vl_memsize_t length) |
Copies a block of memory to the end of the specified arena allocation. | |
vl_arena_ptr | vlArenaMemAppend (vl_arena *arena, vl_arena_ptr dstPtr, const void *src, vl_memsize_t length) |
Copies a block of memory to the beginning of the specified arena allocation. | |
vl_transient * | vlArenaMemSample (vl_arena *arena, vl_arena_ptr ptr) |
Sampling function that calculates a transient pointer into the specified arena. | |
vl_memsize_t | vlArenaMemSize (vl_arena *arena, vl_arena_ptr ptr) |
Get the size of a memory block allocated in a VL arena. | |
vl_memsize_t | vlArenaTotalCapacity (vl_arena *arena) |
Get the total capacity of the arena. | |
vl_memsize_t | vlArenaTotalFree (vl_arena *arena) |
Get the total amount of free memory in the arena. | |
void vlArenaClear | ( | vl_arena * | arena | ) |
Clears all the elements in the given arena.
This function removes all the elements in the arena, making it empty. The memory allocated for the elements is not released by this function.
arena | Pointer to the vl_arena structure. |
Clones the specified arena to another.
Clones the entirety of the src arena to the dest arena.
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.
src | pointer |
dest | pointer |
void vlArenaDelete | ( | vl_arena * | arena | ) |
Deletes the given VL arena, freeing all allocated memory.
arena | Pointer to the VL arena to be deleted. |
void vlArenaFree | ( | vl_arena * | arena | ) |
Frees memory allocated by an arena instance.
arena | Pointer to the arena instance to be freed. |
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 | The vl_arena structure to be initialized. |
initialSize | The initial size of the arena. |
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.
arena | A pointer to the arena from which memory will be allocated. |
size | The size of the memory to be allocated in bytes. |
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 beginning of the specified arena allocation.
This function handles the case wherein the specified source pointer resides within the arena.
arena | pointer |
dst | arena pointer |
src | memory to copy from |
length | number of bytes from src |
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.
arena | The vl_arena structure representing the arena. |
ptr | The pointer to the memory block to be freed. |
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 end of the specified arena allocation.
This function handles the case wherein the specified source pointer resides within the arena.
arena | pointer |
dst | arena pointer |
src | memory to copy from |
length | number of bytes from src |
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.
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. |
vl_transient * vlArenaMemSample | ( | vl_arena * | arena, |
vl_arena_ptr | ptr ) |
Sampling function that calculates a transient pointer into the specified arena.
arena | The arena on which the operation is performed. |
ptr | The arena pointer indicating the memory location on the arena. |
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 | Pointer to the VL arena. |
ptr | Pointer to the memory block. |
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.
initialSize | The initial size of the arena. |
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.
arena | pointer |
numBytes | total bytes to reserve |
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 | Pointer to the arena structure. |
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.
arena | The pointer to the arena structure. |