Skip to content
HeapAllocatorInitAligned

HeapAllocatorInitAligned

Description

Same as HeapAllocatorInit() but with a caller-supplied alignment floor (N, in bytes). N == 0 is silently coerced to

  1. Allocations whose effective alignment exceeds 16 are routed to

the XL passthrough so the bitmap-classed path can stay tied to its 16-byte slot grid.

HeapAllocator h = HeapAllocatorInitAligned(64);

Success

Returns a fully-initialised HeapAllocator value with the requested alignment floor recorded in base.alignment.

Failure

Cannot fail at macro-expansion time.

Usage example (Cross-references)

Usage examples (Cross-references)
    
    static bool test_overaligned_alloc(void) {
        HeapAllocator heap  = HeapAllocatorInitAligned(64);
        Allocator    *alloc = ALLOCATOR_OF(&heap);
    
        DefaultAllocator alloc    = DefaultAllocatorInit();
        HeapAllocator    aligned8 = HeapAllocatorInitAligned(8);
    
        // Create a vector of integers
    
        DefaultAllocator alloc    = DefaultAllocatorInit();
        HeapAllocator    aligned8 = HeapAllocatorInitAligned(8);
    
        // Create a vector of integers with default alignment (1)
        WriteFmt("Testing element stride round-trips values\n");
    
        HeapAllocator alloc = HeapAllocatorInitAligned(16);
    
        typedef Vec(u32) U32Vec;
        WriteFmt("Testing Graph aligned init and node id layout\n");
    
        HeapAllocator alloc = HeapAllocatorInitAligned(32);
    
        typedef Graph(int) IntGraph;
        WriteFmt("Testing VecInit with aligned allocator\n");
    
        HeapAllocator aligned4  = HeapAllocatorInitAligned(4);
        HeapAllocator aligned16 = HeapAllocatorInitAligned(16);
    
        HeapAllocator aligned4  = HeapAllocatorInitAligned(4);
        HeapAllocator aligned16 = HeapAllocatorInitAligned(16);
    
        // Test with int type and 4-byte alignment
        WriteFmt("Testing VecInit with aligned allocator and deep copy\n");
    
        HeapAllocator aligned8 = HeapAllocatorInitAligned(8);
    
        // Test with struct type, custom copy/deinit functions, and 8-byte alignment
        // allocator's settings.
        HeapAllocator h_default = HeapAllocatorInit();
        HeapAllocator h8        = HeapAllocatorInitAligned(8);
        HeapAllocator h16       = HeapAllocatorInitAligned(16);
        HeapAllocator h32       = HeapAllocatorInitAligned(32);
        HeapAllocator h_default = HeapAllocatorInit();
        HeapAllocator h8        = HeapAllocatorInitAligned(8);
        HeapAllocator h16       = HeapAllocatorInitAligned(16);
        HeapAllocator h32       = HeapAllocatorInitAligned(32);
        HeapAllocator h64       = HeapAllocatorInitAligned(64);
        HeapAllocator h8        = HeapAllocatorInitAligned(8);
        HeapAllocator h16       = HeapAllocatorInitAligned(16);
        HeapAllocator h32       = HeapAllocatorInitAligned(32);
        HeapAllocator h64       = HeapAllocatorInitAligned(64);
        HeapAllocator h16       = HeapAllocatorInitAligned(16);
        HeapAllocator h32       = HeapAllocatorInitAligned(32);
        HeapAllocator h64       = HeapAllocatorInitAligned(64);
    
        h_default.base.retry_limit = 17;
        alloc.base.retry_limit = 31;
    
        HeapAllocator aligned_8     = HeapAllocatorInitAligned(8);
        aligned_8.base.retry_limit  = 31;
        HeapAllocator aligned_16    = HeapAllocatorInitAligned(16);
        HeapAllocator aligned_8     = HeapAllocatorInitAligned(8);
        aligned_8.base.retry_limit  = 31;
        HeapAllocator aligned_16    = HeapAllocatorInitAligned(16);
        aligned_16.base.retry_limit = 31;
        HeapAllocator aligned_32    = HeapAllocatorInitAligned(32);
        HeapAllocator aligned_16    = HeapAllocatorInitAligned(16);
        aligned_16.base.retry_limit = 31;
        HeapAllocator aligned_32    = HeapAllocatorInitAligned(32);
        aligned_32.base.retry_limit = 31;
        HeapAllocator aligned_64    = HeapAllocatorInitAligned(64);
        HeapAllocator aligned_32    = HeapAllocatorInitAligned(32);
        aligned_32.base.retry_limit = 31;
        HeapAllocator aligned_64    = HeapAllocatorInitAligned(64);
        aligned_64.base.retry_limit = 31;
Last updated on