Skip to content

File syn_slab.h

FileList > src > syntropic > util > syn_slab.h

Go to the source code of this file

Multi-Class Slab Memory Allocator. More...

  • #include "../common/syn_defs.h"
  • #include <stdbool.h>
  • #include <stddef.h>
  • #include <stdint.h>

Classes

Type Name
struct SYN_SlabAllocator
Multi-Class Slab Allocator.
struct SYN_SlabClass
Single Slab Size Class Descriptor.
struct SYN_SlabStats
Slab Allocator Statistics.

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 SYN_SLAB_MAX_CLASSES 8U

Detailed Description

Partitions a single caller-provided static memory pool into multiple fixed-size slab block classes (e.g. 16B, 64B, 256B). Allocations and frees execute in deterministic O(1) time without heap fragmentation.

Public Functions Documentation

function syn_slab_alloc

Allocate a block from the optimal slab class.

void * syn_slab_alloc (
    SYN_SlabAllocator * slab,
    size_t size
) 

Parameters:

  • slab Allocator context.
  • size Requested allocation size in bytes.

Returns:

Pointer to allocated block, or NULL if unavailable.


function syn_slab_free

Free a previously allocated slab block.

SYN_Status syn_slab_free (
    SYN_SlabAllocator * slab,
    void * ptr
) 

Parameters:

  • slab Allocator context.
  • ptr Pointer to block to free.

Returns:

SYN_OK on success, or SYN_INVALID_PARAM.


function syn_slab_get_stats

Retrieve current allocator usage statistics.

SYN_Status syn_slab_get_stats (
    const SYN_SlabAllocator * slab,
    SYN_SlabStats * stats
) 

Parameters:

  • slab Allocator context.
  • stats Output 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:

  • slab Pointer to allocator context.
  • backing_memory Pointer to static backing array.
  • total_size Size of backing memory in bytes.
  • block_sizes Array of desired block sizes (e.g. {16, 64, 256}).
  • blocks_per_class Array of block counts for each class.
  • num_classes Number of classes (1 to SYN_SLAB_MAX_CLASSES).

Returns:

SYN_OK on success.


Macro Definition Documentation

define SYN_SLAB_MAX_CLASSES

#define SYN_SLAB_MAX_CLASSES `8U`

Maximum slab size classes per allocator instance.



The documentation for this class was generated from the following file src/syntropic/util/syn_slab.h