std1.0.0-beta-7 SafeC docs

std :: alloc::allocator

Struct std::CountingAllocator

#include <std/alloc/allocator.h> source

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

§&A innersource

the allocator doing the work (not owned)

§unsigned long allocssource

alloc calls that returned a block

§unsigned long freessource

dealloc calls with a non-null block

§unsigned long failuressource

alloc calls that returned null

§unsigned long bytessource

bytes requested by the successful allocs

Methods

§static struct CountingAllocator<A> over(&A inner)source · definition
§?&heap unsigned char alloc(unsigned long size, unsigned long align)source · definition
§void dealloc(?&heap unsigned char ptr)source · definition
§unsigned long live() constsource · definition

Blocks handed out and not given back yet.