Skip to main content

Crate concinnity_memory

Crate concinnity_memory 

Source
Expand description

The engine’s allocation layer: what the process is holding, who is holding it, and the allocators that hand memory out in bulk instead of one block at a time.

Five things live here, in files that do not depend on each other:

counters the global heap’s live / peak / churn, sharded per thread and driven by TrackingAlloc (tracking) ledger tagged byte accounting – textures, meshes, audio, scratch – in host and device memory, against optional budgets arena a bump allocator for per-frame working memory pool fixed-capacity storage for a population that churns inline_vec a sequence that keeps its first element inline, for the many per-entity collections that hold exactly one thing

The counters measure the Rust heap, not “the engine”. They see every allocation the process makes through Rust – engine, tools, and third-party crates alike – and none of the memory Rust never allocated: GPU driver allocations, mapped asset files, thread stacks, and the binary image itself. The gap between MemStats::live_bytes and the process resident size is that non-Rust remainder, not untracked engine waste. The ledger is the other half of that story: it explains a portion of both realms by name, and what it explains is always a floor, since it holds only what someone reports.

GPU memory is accounted here and allocated elsewhere, deliberately. A device allocator returns a heap and an offset rather than a pointer, its frees must wait for frames in flight to retire, and its placement rules differ per backend; that belongs behind concinnity-device. What both sides share is the vocabulary they report into, which is what lets one readout show RAM and VRAM through the same lens.

Macros§

install_global_allocator
Install TrackingAlloc over the system allocator as this program’s #[global_allocator].

Structs§

Arena
A bump allocator over one fixed reservation, reset as a whole.
ArenaVec
A vector over a reservation in an arena: pushes cost a write, and the whole thing disappears when the arena resets.
InlineVec
A sequence holding its first element inline and spilling to the heap beyond that.
Ledger
The tagged accounting itself. One process-global instance backs the engine (crate::ledger()); the type is public so the accounting is testable on its own instance.
LedgerSnapshot
Every tag’s usage in every realm, read in one pass.
MemStats
A snapshot of the tracked heap. Counters are relaxed, so the fields are individually accurate but need not agree with each other to the byte under concurrent allocation.
Pool
A fixed-capacity slot pool handing out generation-checked handles.
PoolHandle
A reference to one object in a pool. Copyable and small: pass it around instead of the object.
SizeClass
One size class as read at a moment.
TrackingAlloc
A GlobalAlloc that counts allocations and forwards them to A.

Enums§

InlineVecIntoIter
By-value iterator over an InlineVec, produced by into_iter.
MemTag
What a block of memory is for. Other is the honest bucket for a reporter that has no better answer; it is not a catch-all for everything unreported, since the ledger only ever holds what someone reports into it.
Realm
Which memory a report is about. The two are counted separately because they are separately budgeted and separately exhausted: a host allocation and a device allocation for the same texture are two different costs.

Functions§

alloc_count
Allocations made since process start, or None under the same condition as stats. Cheaper than a full stats read; the frame loop samples this around every system step in dev builds to attribute per-frame allocation churn.
ledger
The process-wide tagged accounting. Subsystems report what they hold into it and readouts break the process down by tag; unlike stats, it is live whether or not a binary installed the tracking allocator.
size_classes
The heap’s size-class histogram, or None when the crate was built without the detail feature.
stats
The tracked heap as of now, or None when no binary installed TrackingAlloc as its #[global_allocator].