File syn_slab.c¶
FileList > src > syntropic > util > syn_slab.c
Go to the source code of this file
Multi-Class Slab Memory Allocator implementation.
#include "syn_slab.h"#include <string.h>
Public Functions¶
| Type | Name |
|---|---|
| void * | syn_slab_alloc (SYN_SlabAllocator * slab, size_t size) Allocate a block from the optimal slab class. |
| SYN_Status | syn_slab_free (SYN_SlabAllocator * slab, void * ptr) Free a previously allocated slab block. |
| SYN_Status | syn_slab_get_stats (const SYN_SlabAllocator * slab, SYN_SlabStats * stats) Retrieve current allocator usage statistics. |
| SYN_Status | syn_slab_init (SYN_SlabAllocator * slab, void * backing_memory, size_t total_size, const size_t * block_sizes, const size_t * blocks_per_class, size_t num_classes) Initialize a Multi-Class Slab Allocator. |
Macros¶
| Type | Name |
|---|---|
| define | ALIGN4 (x) (((x) + 3u) & ~3u) |
Public Functions Documentation¶
function syn_slab_alloc¶
Allocate a block from the optimal slab class.
Parameters:
slabAllocator context.sizeRequested allocation size in bytes.
Returns:
Pointer to allocated block, or NULL if unavailable.
function syn_slab_free¶
Free a previously allocated slab block.
Parameters:
slabAllocator context.ptrPointer to block to free.
Returns:
SYN_OK on success, or SYN_INVALID_PARAM.
function syn_slab_get_stats¶
Retrieve current allocator usage statistics.
Parameters:
slabAllocator context.statsOutput statistics structure.
Returns:
SYN_OK on success.
function syn_slab_init¶
Initialize a Multi-Class Slab Allocator.
SYN_Status syn_slab_init (
SYN_SlabAllocator * slab,
void * backing_memory,
size_t total_size,
const size_t * block_sizes,
const size_t * blocks_per_class,
size_t num_classes
)
Parameters:
slabPointer to allocator context.backing_memoryPointer to static backing array.total_sizeSize of backing memory in bytes.block_sizesArray of desired block sizes (e.g. {16, 64, 256}).blocks_per_classArray of block counts for each class.num_classesNumber of classes (1 to SYN_SLAB_MAX_CLASSES).
Returns:
SYN_OK on success.
Macro Definition Documentation¶
define ALIGN4¶
The documentation for this class was generated from the following file src/syntropic/util/syn_slab.c