Skip to main content

Module alloc

Module alloc 

Source
Expand description

How many allocations a stretch of a blue program made, and how many bytes.

blue profile reports time per definition; this is the other half of what a definition costs (theory/BLUE-MEMORY.md §VI M0: you cannot configure what you cannot account for). One counter, read at two points: a caller snapshots allocations when an activation enters and again when it leaves, and the difference is what that activation allocated, everything it called included. Subtracting what its callees allocated gives the exclusive figure, exactly as the profiler does with time.

Counting is a GlobalAlloc over System that counts each allocation on the thread that made it. A binary opts in with one line:

ⓘ
#[global_allocator]
static ALLOC: blue_lang_runtime::alloc::Counting = blue_lang_runtime::alloc::Counting;

The count is per thread so a profile of one interpreter is not charged for another thread’s work, and it costs one thread-local access per allocation and per free (so a room can say what it left live). Until a binary installs Counting, allocations answers None: a program that was never counted reads as unmeasured, never as having allocated nothing.

The same access charges an Account: the live bytes one evaluation, or one blue process, holds, against the bound max_alloc_bytes sets (crate::memory). charged_to makes an account the one running on this thread for a scope, so the tree-walker’s root, each process slice and each message in transit are charged to whoever owns them.

Structs§

Account
The live bytes one account holds, and the bound it is held to.
Allocations
Allocations made and bytes requested on one thread, from its start.
Counting
The system allocator, counting what each thread allocates. See the module documentation for how a binary installs it.

Functions§

allocations
This thread’s running totals, or None when Counting is not the global allocator of this binary.
apart
Run f charged to no evaluation, and answer the bytes it left live.
bound
The bound of the account running now: None when it has none, or when Counting is not installed and no bound could be enforced.
charge_held
Charge bytes to the account running now, as if it had allocated them.
charged_to
Run f with every allocation and free this thread makes charged to account instead of the account running now, which is set aside and put back unchanged when f returns or unwinds.
exhausted
Whether the account running now has passed its bound.