Expand description
Static pre-allocated bounded #[global_allocator] with hard caps
on per-allocation size and total live block count.
See FEAT_0040 and REQ_0300..REQ_0304 for the design contract.
§Quick start
ⓘ
use taktora_bounded_alloc::declare_global_allocator;
// Declares a `#[global_allocator]` static named `ALLOC` with a
// 512 × 1024-byte arena. Maximum per-allocation size is 1024
// bytes; maximum live blocks is 512.
declare_global_allocator!(ALLOC, 512, 1024);
fn main() {
let s = String::from("hello");
assert_eq!(ALLOC.alloc_count(), 1);
drop(s);
assert_eq!(ALLOC.dealloc_count(), 1);
}§Lock-after-init
Call ALLOC.lock() once the program reaches its steady-state
point (e.g. after Executor::build). Any subsequent allocation
call panics — which under panic = "abort" aborts the process,
catching stray heap activity that escaped review.
ⓘ
ALLOC.lock();
let _ = String::from("this aborts the process");The consuming binary’s Cargo.toml must set
[profile.release] panic = "abort" (and [profile.dev] if dev
builds also need the guarantee) — otherwise the panic itself
will allocate the unwinder’s payload string.
Macros§
- bounded_
allocator - Construct a const-evaluable
BoundedAllocatorexpression with the bitmap word count computed automatically. Useful in regular (non-global-allocator)staticdeclarations and tests. - declare_
global_ allocator - Declare a
static BoundedAllocatorregistered as#[global_allocator], computing the bitmap word count fromMAX_BLOCKSautomatically.
Structs§
- Bounded
Allocator - Static pre-allocated bounded global allocator.
- Counting
Allocator #[global_allocator]-compatible wrapper around the system allocator that counts every successful allocation and deallocation while a thread-sharedTRACKINGflag is set.