Skip to content
DebugAllocatorConfig

DebugAllocatorConfig

Description

Runtime configuration. Use DEBUG_ALLOCATOR_DEFAULTS for a sensible all-checks-on baseline.

Usage example (Cross-references)

Usage examples (Cross-references)
    #    if FEATURE_DEFAULT_ALLOC_DEBUG_PAGE_BACKED
    #        define DefaultAllocatorInit()                                                                                 \
                DebugAllocatorInitWith(((DebugAllocatorConfig) {.capture_traces      = true,                               \
                                                                .detect_overflow     = true,                               \
                                                                .force_page_backing  = true,                               \
            ///
            bool track_freed_history;
        } DebugAllocatorConfig;
    
    ///
    ///
    #define DEBUG_ALLOCATOR_DEFAULTS                                                                                       \
        ((DebugAllocatorConfig) {.capture_traces      = true,                                                              \
                                 .detect_overflow     = true,                                                              \
                                 .force_page_backing  = false,                                                             \
            HeapAllocator        meta;
            PageAllocator        page;
            DebugAllocatorConfig config;
            DebugRecordMap       live;
            DebugFreedVec        freed;
    // detection (LiveCount / LiveBytes) is unchanged.
    #define LEAK_CFG                                                                                                       \
        ((DebugAllocatorConfig) {.capture_traces = false, .detect_overflow = false, .track_freed_history = false})
    
    // =============================================================================
    
    static DebugAllocator blind_debug_alloc(void) {
        DebugAllocatorConfig cfg = {.capture_traces = false, .detect_overflow = false, .track_freed_history = false};
        return DebugAllocatorInitWith(cfg);
    }
    // capture / overflow / freed-history bookkeeping, just live-count tracking.
    static DebugAllocator make_lean_debug_allocator(void) {
        DebugAllocatorConfig cfg = {.capture_traces = false, .detect_overflow = false, .track_freed_history = false};
        return DebugAllocatorInitWith(cfg);
    }
        // When track_freed_history = false, freed Vec stays empty even
        // after many frees -- and allocator is still functional.
        DebugAllocatorConfig cfg = DEBUG_ALLOCATOR_DEFAULTS;
        cfg.track_freed_history  = false;
        DebugAllocator dbg       = DebugAllocatorInitWith(cfg);
    
    bool test_debug_page_backed_alloc_free(void) {
        DebugAllocatorConfig cfg = DEBUG_ALLOCATOR_DEFAULTS;
        cfg.force_page_backing   = true;
        DebugAllocator dbg       = DebugAllocatorInitWith(cfg);
    
    bool test_ad1_freed_free_trace_n_zero_when_no_capture(void) {
        DebugAllocatorConfig cfg = DEBUG_ALLOCATOR_DEFAULTS;
        cfg.capture_traces       = false;
        DebugAllocator dbg       = DebugAllocatorInitWith(cfg);
    
    bool test_ad1_freed_free_trace_n_capped_to_depth(void) {
        DebugAllocatorConfig cfg = DEBUG_ALLOCATOR_DEFAULTS;
        cfg.trace_depth          = 2;
        DebugAllocator dbg       = DebugAllocatorInitWith(cfg);
    
    bool test_ad1_freed_free_trace_n_clamped_to_max(void) {
        DebugAllocatorConfig cfg = DEBUG_ALLOCATOR_DEFAULTS;
        cfg.trace_depth          = 20;
        DebugAllocator dbg       = DebugAllocatorInitWith(cfg);
    // lifts the working depth to 16 (clamp) captures up to 16.
    bool test_ad2_trace_depth_respected(void) {
        DebugAllocatorConfig cfg = DEBUG_ALLOCATOR_DEFAULTS;
        cfg.trace_depth          = 4; // below MAX_TRACE
        DebugAllocator dbg       = DebugAllocatorInitWith(cfg);
    // and record > 16 frames.
    bool test_ad2_trace_depth_clamped_to_max(void) {
        DebugAllocatorConfig cfg = DEBUG_ALLOCATOR_DEFAULTS;
        cfg.trace_depth          = 32; // above MAX_TRACE -> must clamp to 16
        DebugAllocator dbg       = DebugAllocatorInitWith(cfg);
    
    bool test_af_free_trace_depth_clamped(void) {
        DebugAllocatorConfig cfg = DEBUG_ALLOCATOR_DEFAULTS;
        cfg.capture_traces       = true;
        cfg.trace_depth          = 32; // above DEBUG_ALLOCATOR_MAX_TRACE (16)
    // capture, no overflow canaries, no freed history -- just the live count.
    static DebugAllocator make_lean_dbg(void) {
        return DebugAllocatorInitWith(((DebugAllocatorConfig) {
            .capture_traces      = false,
            .detect_overflow     = false,
    // LiveBytes are still tracked, so leak detection is unchanged.
    #define LEAK_CFG                                                                                                       \
        ((DebugAllocatorConfig) {.capture_traces = false, .detect_overflow = false, .track_freed_history = false})
    
    // ---------------------------------------------------------------------------
    // Lean DebugAllocator config -- leak detection only, no trace capture, to
    // keep the leak tests fast.
    static DebugAllocatorConfig lean_dbg_cfg(void) {
        return (DebugAllocatorConfig) {.capture_traces = false, .detect_overflow = false, .track_freed_history = false};
    }
    // keep the leak tests fast.
    static DebugAllocatorConfig lean_dbg_cfg(void) {
        return (DebugAllocatorConfig) {.capture_traces = false, .detect_overflow = false, .track_freed_history = false};
    }
    #include "../Util/TestRunner.h"
    
    static DebugAllocatorConfig blind_cfg(void) {
        return (DebugAllocatorConfig) {.capture_traces = false, .detect_overflow = false, .track_freed_history = false};
    }
    
    static DebugAllocatorConfig blind_cfg(void) {
        return (DebugAllocatorConfig) {.capture_traces = false, .detect_overflow = false, .track_freed_history = false};
    }
    // detection (LiveCount / LiveBytes) is unchanged.
    #define LEAK_CFG                                                                                                       \
        ((DebugAllocatorConfig) {.capture_traces = false, .detect_overflow = false, .track_freed_history = false})
    
    // ---------------------------------------------------------------------------
    // Lean leak-checking DebugAllocator config (no traces / overflow / history).
    static DebugAllocator leak_alloc(void) {
        DebugAllocatorConfig cfg = DEBUG_ALLOCATOR_DEFAULTS;
        cfg.capture_traces       = false;
        cfg.detect_overflow      = false;
    // history. We only need the live-allocation round-trip count.
    static DebugAllocator kv_lean_debug_allocator(void) {
        DebugAllocatorConfig cfg = {.capture_traces = false, .detect_overflow = false, .track_freed_history = false};
        return DebugAllocatorInitWith(cfg);
    }
Last updated on