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(); void *p = AllocatorAlloc(&page, 64 * 1024, true); AllocatorFree(&page, p);

Success

Returns a fully-initialised PageAllocator value. No OS calls happen at init; the first allocation triggers the first kernel page map.

Failure

Cannot fail at macro-expansion time.

Usage example (Cross-references)

Usage examples (Cross-references)
            .heap         = HeapAllocatorInit(),                                                                           \
            .meta         = HeapAllocatorInit(),                                                                           \
            .page         = PageAllocatorInit(),                                                                           \
            .config       = (_cfg),                                                                                        \
            .live         = DEBUG_LIVE_LIT,                                                                                \
    
    bool test_page_protect_roundtrip(void) {
        PageAllocator page = PageAllocatorInit();
        Allocator    *base = ALLOCATOR_OF(&page);
    
    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);
        // PageAllocator backs Vec via the generic Allocator dispatch.
        // Exercises the internal descriptor table across multiple grows.
        PageAllocator alloc = PageAllocatorInit();
        typedef Vec(int) IntVec;
        IntVec v  = VecInit(&alloc);
        // both, plus the descriptor tables.
        bool          ok         = true;
        PageAllocator alloc      = PageAllocatorInit();
        Allocator    *alloc_base = ALLOCATOR_OF(&alloc);
        size          page       = PageAllocatorPageSize(&alloc);
Last updated on