AllocatorStats
Description
Per-allocator memory-pressure counters. Every typed allocator (Heap, Page, Arena, Slab, Budget, Debug) updates these inline at its own allocate / resize / remap / deallocate success and failure points, so the counters move the same way whether the caller used the typed-direct call (AllocatorAlloc(&heap, ...)) or the dyn dispatch wrapper. Read via the Allocator* macros declared below (AllocatorBytesInUse(a) etc.); reset via AllocatorResetStats(...).
Fields
| Name | Description |
|---|---|
bytes_requested |
cumulative bytes ever requested across allocate + successful resize/remap (does not decrease on free). Tracks the user’s raw bytes argument across the API. |
bytes_in_use |
outstanding effective bytes reserved by the allocator on behalf of the caller – what each typed *_allocator_deallocate will release when the caller frees the pointer. Concretely: the slot size for binned allocators (Heap S/M/L, Slab, Budget), the page-rounded mapping length for page-grain allocators (Page, Heap XL), the alignment-padded bump width for the arena. Allocator-side units, not user-side units – alloc bumps and free draws stay in lock-step so the counter is consistent across alloc / free pairs. resize and in-place remap do NOT touch this counter – a successful in-place resize doesn’t change the effective reservation, so it’s a no-op for accounting. An XL remap that actually resized the kernel mapping (same ptr or relocated) DOES adjust the counter by the page-count delta. When a typed remap falls back to allocate-new + free-old, the inner calls each update the counter individually (alloc bumps by new effective, free draws down by old effective). |
peak_bytes_in_use |
historical max of bytes_in_use. |
allocations |
count of successful allocate calls. |
reallocations |
count of successful in-place resize / in-place remap calls. Remaps that fell back to alloc+free are counted as +1 allocation +1 deallocation, not as a reallocation. |
deallocations |
count of deallocate calls. |
failed_allocations |
count of allocate / resize / remap calls that returned NULL or 0. |
Usage example (Cross-references)
Usage examples (Cross-references)
- In
Allocator.h:114:
u64 deallocations;
u64 failed_allocations;
} AllocatorStats;
#endif- In
Allocator.h:155:
size footprint_bytes;
#if FEATURE_ALLOC_STATS
AllocatorStats stats;
#endif
};- In
Allocator.c:108:
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.
Last updated on