Skip to content
DebugAllocatorCreate

DebugAllocatorCreate

Description

Construct a DebugAllocator wrapping parent. Returns a pointer allocated through meta_alloc; the same meta_alloc must be passed back to DebugAllocatorDestroy so the handle and the internal maps can be released through the same allocator.

Parameters

Name Direction Description
parent in Backing allocator to audit (user allocations flow through it).
meta_alloc in Allocator for the DebugAllocator’s own bookkeeping (live / freed maps, trace storage). Must outlive the returned DebugAllocator.

Success

Returns a configured handle ready for use through ALLOCATOR_OF(handle) like any other allocator.

Failure

Returns NULL on allocation failure inside meta_alloc.

Usage example (Cross-references)

Usage examples (Cross-references)
        HeapAllocator meta    = HeapAllocatorInit();
    
        DebugAllocator *dbg = DebugAllocatorCreate(ALLOCATOR_OF(&backing), ALLOCATOR_OF(&meta));
        if (!dbg) {
            return false;
        HeapAllocator meta    = HeapAllocatorInit();
    
        DebugAllocator *dbg  = DebugAllocatorCreate(ALLOCATOR_OF(&backing), ALLOCATOR_OF(&meta));
        Allocator      *adbg = ALLOCATOR_OF(dbg);
        HeapAllocator meta    = HeapAllocatorInit();
    
        DebugAllocator *dbg  = DebugAllocatorCreate(ALLOCATOR_OF(&backing), ALLOCATOR_OF(&meta));
        Allocator      *adbg = ALLOCATOR_OF(dbg);
        HeapAllocator meta    = HeapAllocatorInit();
    
        DebugAllocator *dbg  = DebugAllocatorCreate(ALLOCATOR_OF(&backing), ALLOCATOR_OF(&meta));
        Allocator      *adbg = ALLOCATOR_OF(dbg);
    DebugAllocator *DebugAllocatorCreateWith(Allocator *parent, Allocator *meta_alloc, DebugAllocatorConfig config) {
        if (!parent || !meta_alloc) {
            LOG_ERROR("DebugAllocatorCreate: parent and meta_alloc are required");
            return NULL;
        }
        DebugAllocator *dbg = (DebugAllocator *)AllocatorAlloc(meta_alloc, sizeof(DebugAllocator), true);
        if (!dbg) {
            LOG_ERROR("DebugAllocatorCreate: handle allocation failed");
            return NULL;
        }
    }
    
    DebugAllocator *DebugAllocatorCreate(Allocator *parent, Allocator *meta_alloc) {
        return DebugAllocatorCreateWith(parent, meta_alloc, DEBUG_ALLOCATOR_DEFAULTS);
    }
Last updated on