Skip to content
BudgetAllocatorSlotCount

BudgetAllocatorSlotCount

Description

Total slot capacity carved out of the caller’s buffer at init. Fixed for the lifetime of the allocator: subtract live allocations to get the remaining budget.

Usage example (Cross-references)

Usage examples (Cross-references)
        Allocator      *alloc    = ALLOCATOR_OF(&bp);
    
        bool ok = BudgetAllocatorSlotCount(&bp) > 0;
        for (size i = 0; ok && i < BudgetAllocatorSlotCount(&bp); i++) {
            if (!AllocatorAlloc(alloc, sizeof(Node), false))
    
        bool ok = BudgetAllocatorSlotCount(&bp) > 0;
        for (size i = 0; ok && i < BudgetAllocatorSlotCount(&bp); i++) {
            if (!AllocatorAlloc(alloc, sizeof(Node), false))
                ok = false;
        u64             buf[4] = {0}; // 32 bytes -> exactly one 16-byte slot
        BudgetAllocator bp     = BudgetAllocatorInit((u8 *)buf, sizeof(buf), 16);
        if (BudgetAllocatorSlotCount(&bp) != 1)
            return false;             // precondition: the targeting needs a single slot
Last updated on