Skip to content

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.

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 ALIGN4

#define ALIGN4 (
    x
) `(((x) + 3u) & ~3u)`


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