Skip to content
PageAllocatorInit

PageAllocatorInit

Description

Initialize a PageAllocator with default settings (alignment = 1, the natural page-grain alignment of mmap/VirtualAlloc). Use as a designated-initializer:

PageAllocator page = PageAllocatorInit(); Vec(int) v = VecInit(&page);

Usage example (Cross-references)

Usage examples (Cross-references)
    
    static bool test_basic_alloc_and_free(void) {
        PageAllocator alloc      = PageAllocatorInit();
        Allocator    *alloc_base = ALLOCATOR_OF(&alloc);
        void         *ptr        = AllocatorAlloc(alloc_base, 128, true);
    
    static bool test_realloc_grow_then_shrink(void) {
        PageAllocator alloc      = PageAllocatorInit();
        Allocator    *alloc_base = ALLOCATOR_OF(&alloc);
        size          page       = PageAllocatorPageSize(&alloc);
    
    static bool test_vec_with_page_allocator(void) {
        PageAllocator alloc = PageAllocatorInit();
        typedef Vec(int) IntVec;
        IntVec v  = VecInit(&alloc);
            .bins        = {0},                                                                                            \
            .chunks_head = NULL,                                                                                           \
            .page        = PageAllocatorInit()                                                                             \
        })
            .bins        = {0},                                                                                            \
            .chunks_head = NULL,                                                                                           \
            .page        = PageAllocatorInit()                                                                             \
        })
            .last_ptr  = NULL,                                                                                             \
            .last_size = 0,                                                                                                \
            .page      = PageAllocatorInit()                                                                               \
        })
            .last_ptr  = NULL,                                                                                             \
            .last_size = 0,                                                                                                \
            .page      = PageAllocatorInit()                                                                               \
        })
            .slot_size       = (slot_size_bytes),                                                                          \
            .slots_per_chunk = MISRA_SLAB_DEFAULT_CHUNK_SLOTS,                                                             \
            .page            = PageAllocatorInit()                                                                         \
        })
            .slot_size       = (slot_size_bytes),                                                                          \
            .slots_per_chunk = MISRA_SLAB_DEFAULT_CHUNK_SLOTS,                                                             \
            .page            = PageAllocatorInit()                                                                         \
        })
Last updated on