Veritable Lasagna
An Allocator & Data Structure Library for C.
Loading...
Searching...
No Matches
vl_linear_pool.c File Reference
#include "vl_linear_pool.h"
#include <stdlib.h>
+ Include dependency graph for vl_linear_pool.c:

Functions

void vlLinearPoolInit (vl_linearpool *pool, vl_memsize_t elementSize)
 Initializes the specified pool instance.
 
void vlLinearPoolFree (vl_linearpool *pool)
 De-initializes the specified pool instance. This will clear up all memory associated with members of the pool. This pool should have been initialized via vlLinearPoolInit.
 
vl_linearpoolvlLinearPoolNew (vl_memsize_t elementSize)
 Allocates and initializes a pool instance.
 
void vlLinearPoolDelete (vl_linearpool *pool)
 De-initializes and deletes the specified pool. This will clear up all memory associated with members of the pool. This pool should have been initialized via vlLinearPoolNew.
 
void vlLinearPoolClear (vl_linearpool *pool)
 
vl_linearpoolvlLinearPoolClone (const vl_linearpool *src, vl_linearpool *dest)
 Clones the specified source pool.
 
void vlLinearPoolReserve (vl_linearpool *pool, vl_memsize_t n)
 Reserves space for n-many elements in the underlying pool buffer.
 
vl_linearpool_idx vlLinearPoolTellIndex (vl_linearpool *pool, const vl_transient *dataPtr)
 Calculates the index of the specified element pointer. May return VL_POOL_INVALID_IDX if the specified pointer is outside the pool buffer range.
 
vl_linearpool_idx vlLinearPoolTake (vl_linearpool *pool)
 
void vlLinearPoolReturn (vl_linearpool *pool, vl_linearpool_idx offset)
 

Function Documentation

◆ vlLinearPoolClear()

void vlLinearPoolClear ( vl_linearpool * pool)

Clears the specified pool. This does not clear any buffers associated with the pool. Rather, this function resets the "next" offset at which the next (new) pool index will be to 0.

Parameters
poolpointer
Complexity O(1) constant.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ vlLinearPoolClone()

vl_linearpool * vlLinearPoolClone ( const vl_linearpool * src,
vl_linearpool * dest )

Clones the specified source pool.

Clones the entirety of the src pool to the dest pool.

The 'src' pool pointer must be non-null and initialized. The 'dest' pool pointer may be null, but if it is not null it must be initialized.

If the 'dest' pool pointer is null, a new pool is initialized via vlLinearPoolNew. Otherwise, its element size is set to the source's and all of its existing data is replaced.

See also
vlLinearPoolNew
Parameters
srcpointer to pool to clone
destpointer to target pool, or NULL
Complexity O(1) constant.
Returns
dest, or pool initialized via vlLinearPoolNew
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ vlLinearPoolDelete()

void vlLinearPoolDelete ( vl_linearpool * pool)

De-initializes and deletes the specified pool. This will clear up all memory associated with members of the pool. This pool should have been initialized via vlLinearPoolNew.

See also
vlLinearPoolNew
Parameters
poolpointer
Complexity O(1) constant.
+ Here is the call graph for this function:

◆ vlLinearPoolFree()

void vlLinearPoolFree ( vl_linearpool * pool)

De-initializes the specified pool instance. This will clear up all memory associated with members of the pool. This pool should have been initialized via vlLinearPoolInit.

See also
vlLinearPoolInit
Parameters
pool
Complexity O(1) constant.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ vlLinearPoolInit()

void vlLinearPoolInit ( vl_linearpool * pool,
vl_memsize_t elementSize )

Initializes the specified pool instance.

This pool should be freed via vlLinearPoolFree.

See also
vlLinearPoolFree
Parameters
poolpointer
elementSizesize of each element, in bytes.
Complexity O(1) constant.
+ Here is the caller graph for this function:

◆ vlLinearPoolNew()

vl_linearpool * vlLinearPoolNew ( vl_memsize_t elementSize)

Allocates and initializes a pool instance.

This pool should later be deleted via vlLinearPoolDelete.

See also
vlLinearPoolDelete
Parameters
elementSizesize of each element, in bytes.
Complexity O(1) constant.
Returns
pointer to pool instance
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ vlLinearPoolReserve()

void vlLinearPoolReserve ( vl_linearpool * pool,
vl_memsize_t n )

Reserves space for n-many elements in the underlying pool buffer.

This is accomplished by using the standard buffer resizing method for this library, which is doubling the size of the underlying buffer until it is greater than a specified minimum size.

This function will always result in the reallocation of the underlying memory.

Parameters
poolpointer
ntotal elements to reserve space for
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ vlLinearPoolReturn()

void vlLinearPoolReturn ( vl_linearpool * pool,
vl_linearpool_idx offset )

Gives the specified index back to the pool, allowing it to be re-used.

Parameters
pool
offset
Complexity O(1) constant.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ vlLinearPoolTake()

vl_linearpool_idx vlLinearPoolTake ( vl_linearpool * pool)

Takes a new index from the pool, which corresponds to a valid memory location within the pool.

Parameters
poolpointer
Complexity O(1) constant.
Returns
index of new pool item.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ vlLinearPoolTellIndex()

vl_linearpool_idx vlLinearPoolTellIndex ( vl_linearpool * pool,
const vl_transient * dataPtr )

Calculates the index of the specified element pointer. May return VL_POOL_INVALID_IDX if the specified pointer is outside the pool buffer range.

If the underlying pool allocation is implicitly resized, make sure the specified pointer still refers to a current, relevant location in memory. Otherwise, this will return VL_POOL_INVALID_IDX.

Parameters
pool
dataPtr
Complexity O(1) constant.
Returns
index