Skip to content
PoolAllocatorAligned

PoolAllocatorAligned

Description

Create a pool allocator with a custom alignment floor. Slots are at least alignment-aligned. The effective slot size is padded up to a multiple of alignment so the intrusive free-list pointer can be stored inside each slot.

Parameters

Name Direction Description
slot_size in Size of each allocation in bytes.
alignment in Required slot alignment (power of two).

Success

Returns a configured pool allocator descriptor.

Failure

Function cannot fail at creation.

Usage example (Cross-references)

Usage examples (Cross-references)
    
    Allocator PoolAllocator(size slot_size) {
        return PoolAllocatorAligned(slot_size, 1);
    }
    }
    
    Allocator PoolAllocatorAligned(size slot_size, size alignment) {
        u32 flags_slot = slot_size > (size)UINT32_MAX ? UINT32_MAX : (u32)slot_size;
        return (Allocator) {
    
    static bool test_pool_alignment(void) {
        Allocator pool = PoolAllocatorAligned(sizeof(int), 64);
        int      *p    = (int *)AllocatorAlloc(&pool, sizeof(int), true);
        bool      ok   = (p != NULL) && (((uintptr_t)p & 63u) == 0);
Last updated on