Simple Graphics Library 1.0.0.0
Runtime-independent image processing primitives
Loading...
Searching...
No Matches
Memory pool

Allocation from one caller-owned process-wide memory region. More...

Functions

sgl_result_t sgl_memory_pool_initialize (void *memory, sgl_size_t size)
 Registers the process-wide SGL memory pool.
 
sgl_result_t sgl_memory_pool_deinitialize (void)
 Detaches the caller-owned memory pool.
 
void * sgl_malloc (sgl_size_t size)
 Allocates an aligned block from the SGL memory pool.
 
void * sgl_calloc (sgl_size_t count, sgl_size_t size)
 Allocates and zero-initializes an array from the SGL memory pool.
 
void sgl_free (void *memory)
 Releases a block allocated by sgl_malloc() or sgl_calloc().
 

Detailed Description

Allocation from one caller-owned process-wide memory region.

SGL does not fall back to the C runtime heap. Initialize the pool before creating LUTs, queues, thread pools, or invoking an operation that needs temporary storage. Initialization and deinitialization are not concurrent operations; allocation and release are synchronized after initialization.

Function Documentation

◆ sgl_calloc()

void * sgl_calloc ( sgl_size_t  count,
sgl_size_t  size 
)

Allocates and zero-initializes an array from the SGL memory pool.

Parameters
[in]countNumber of elements.
[in]sizeSize of one element in bytes.
Returns
Zero-filled memory, or SGL_NULL when the request cannot be served.

◆ sgl_free()

void sgl_free ( void *  memory)

Releases a block allocated by sgl_malloc() or sgl_calloc().

Parameters
[in,out]memoryAllocation to release; SGL_NULL is accepted.
Note
Pointers outside the active pool are ignored. Each live allocation must be released exactly once; a previously released pointer is invalid.

◆ sgl_malloc()

void * sgl_malloc ( sgl_size_t  size)

Allocates an aligned block from the SGL memory pool.

Parameters
[in]sizeRequested size in bytes.
Returns
Allocated memory, or SGL_NULL for zero size, an uninitialized pool, overflow, or insufficient free space.

◆ sgl_memory_pool_deinitialize()

sgl_result_t sgl_memory_pool_deinitialize ( void  )

Detaches the caller-owned memory pool.

Return values
SGL_SUCCESSNo live allocations remain and the pool was detached.
SGL_FAILUREAt least one allocation is still live.
SGL_ERROR_INVALID_ARGUMENTSThe pool is not initialized.

◆ sgl_memory_pool_initialize()

sgl_result_t sgl_memory_pool_initialize ( void *  memory,
sgl_size_t  size 
)

Registers the process-wide SGL memory pool.

Parameters
[in,out]memoryCaller-owned storage retained until deinitialization.
[in]sizeSize of memory in bytes, including allocator metadata.
Return values
SGL_SUCCESSPool initialized successfully.
SGL_ERROR_INVALID_ARGUMENTSInvalid storage, insufficient size, or an already initialized pool.
Note
The implementation aligns the usable range inside the supplied buffer.