Struct std::CountingAllocator
generic<A: Allocator> struct CountingAllocator {
&A inner;
unsigned long allocs;
unsigned long frees;
unsigned long failures;
unsigned long bytes;
}Forwards every call to the allocator it borrows and counts them: blocks handed out and given back, failed requests, bytes requested. It is an Allocator itself, so it slots in wherever the allocator it wraps would (leak checks in tests, sizing an arena or pool from a real workload).
struct PoolAllocator pool = PoolAllocator::new(65536UL);
struct CountingAllocator<PoolAllocator> c = CountingAllocator::over(&pool);
run_workload(&c); // any generic<A: Allocator> code
if (c.live() != 0UL) { ... } // blocks never given back
Fields
the allocator doing the work (not owned)
alloc calls that returned a block
dealloc calls with a non-null block
alloc calls that returned null
bytes requested by the successful allocs
Methods
Blocks handed out and not given back yet.