Skip to main content

Tally

Trait Tally 

Source
pub trait Tally: Sync {
    // Required methods
    fn grew(&self, size: usize, zeroed: bool);
    fn shrank(&self, size: usize);

    // Provided methods
    fn refuses(&self, size: usize) -> bool { ... }
    fn refuses_realloc(&self, new_size: usize) -> bool { ... }
    fn growing(&self, size: usize) { ... }
    fn failed(&self, size: usize) { ... }
    fn shrunk(&self, old: usize, new: usize) { ... }
}
Expand description

What a test file counts of the blocks its Allocator sees. It is called inside the allocator, so it must not allocate, and it must not panic: a global allocator that unwinds is undefined behaviour (GlobalAlloc’s safety contract), so Allocator ends any unwind out of a tally’s method by aborting the process (review round 6: a tally that panicked unwound through the allocator). A failed assert! or unwrap in a tally is therefore a SIGABRT, after the panic’s message, and never a test failure that unwinds.

Required Methods§

Source

fn grew(&self, size: usize, zeroed: bool)

A block of size bytes became live on a counted thread; zeroed when alloc_zeroed made it.

Source

fn shrank(&self, size: usize)

A block of size bytes was freed on a counted thread: told once System has freed it.

Provided Methods§

Source

fn refuses(&self, size: usize) -> bool

Whether a request of size bytes fails without reaching System, on any thread (a test that refuses huge requests rather than meet the machine’s limit). Never, by default.

Source

fn refuses_realloc(&self, new_size: usize) -> bool

Whether a realloc to new_size bytes fails without reaching System: Self::refuses, by default. A test that refuses one fresh allocation of a size, and never a growth or shrink the code under test makes infallibly, answers false here.

Source

fn growing(&self, size: usize)

A block of size bytes is about to be asked of System on a counted thread (a fresh block, or a realloc’s new one): told before it can be live, so a tally that counts here never holds less than the live heap. Nothing, by default.

Source

fn failed(&self, size: usize)

The request Self::growing told of failed: no block was made. Nothing, by default.

Source

fn shrunk(&self, old: usize, new: usize)

Replace an old block after a successful in-place shrink. There was no provisional new block; coherent tallies update in one event.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl Tally for Ledger

Counted conservatively: a block is counted before System is asked for it and uncounted once System has freed it, so the ledger’s heap is never below the live heap, whatever the threads’ interleaving; a moving realloc counts its new block before the call and drops its old one after success; a failed request is rolled back. A nonmoving shrink holds the old cost through the call, then replaces it in one event.