Skip to content
SlabAllocatorInit

SlabAllocatorInit

Description

Initialize a SlabAllocator with the given slot size. Slot size is padded internally so each slot holds the intrusive free-list pointer.

Usage example (Cross-references)

Usage examples (Cross-references)
    
    static bool test_basic_alloc_and_free(void) {
        SlabAllocator slab       = SlabAllocatorInit(sizeof(Node));
        Allocator    *alloc_base = ALLOCATOR_OF(&slab);
        Node         *a          = (Node *)AllocatorAlloc(alloc_base, sizeof(Node), true);
    
    static bool test_free_then_alloc_recycles(void) {
        SlabAllocator slab       = SlabAllocatorInit(sizeof(Node));
        Allocator    *alloc_base = ALLOCATOR_OF(&slab);
        Node         *a          = (Node *)AllocatorAlloc(alloc_base, sizeof(Node), true);
    
    static bool test_grow_across_chunks(void) {
        SlabAllocator slab       = SlabAllocatorInit(sizeof(Node));
        Allocator    *alloc_base = ALLOCATOR_OF(&slab);
        Node         *slots[600];
    
    static bool test_oversized_request_fails(void) {
        SlabAllocator slab       = SlabAllocatorInit(sizeof(int));
        Allocator    *alloc_base = ALLOCATOR_OF(&slab);
        void         *big        = AllocatorAlloc(alloc_base, 4096, true);
    
    static bool test_free_half_then_realloc(void) {
        SlabAllocator slab       = SlabAllocatorInit(sizeof(Node));
        Allocator    *alloc_base = ALLOCATOR_OF(&slab);
        Node         *slots[200];
Last updated on