Skip to content
AllocatorStats

AllocatorStats

Description

Per-allocator memory-pressure counters. Updated by the dispatch wrappers (AllocatorAlloc / AllocatorRealloc / AllocatorFree) so every typed allocator gets accounting for free. Reset with AllocatorResetStats(...), read with AllocatorGetStats(...).

Fields

Name Description
bytes_requested cumulative bytes ever requested via allocate (does not decrease on free).
bytes_in_use currently outstanding bytes (allocate + realloc-grow - realloc-shrink - deallocate).
peak_bytes_in_use historical max of bytes_in_use.
allocations count of successful allocate calls.
reallocations count of successful reallocate calls.
deallocations count of deallocate calls.
failed_allocations count of allocate / reallocate calls that returned NULL.

Usage example (Cross-references)

Usage examples (Cross-references)
    
    #if MISRA_HAVE_ALLOC_STATS
    AllocatorStats AllocatorGetStats(const Allocator *self) {
        ValidateAllocator(self);
        return self->stats;
        ValidateAllocator(self);
        u64 in_use                  = self->stats.bytes_in_use;
        self->stats                 = (AllocatorStats) {0};
        // Preserve outstanding-allocation accounting so subsequent peak
        // tracking starts from current usage, not zero.
            u64 deallocations;
            u64 failed_allocations;
        } AllocatorStats;
    #endif
            u64                   __magic;
    #if MISRA_HAVE_ALLOC_STATS
            AllocatorStats stats;
    #endif
        };
        /// value; reading does not perturb the counters.
        ///
        AllocatorStats AllocatorGetStats(const Allocator *self);
    
        ///
Last updated on