#[non_exhaustive]pub struct Params<'a> {
pub min_block: usize,
pub growth: (usize, usize),
pub geo_count: usize,
pub extras: &'a [usize],
pub huge_threshold: usize,
}Expand description
Parameters for a size-class scheme, consumed by build_table,
build_size2class and SizeClasses::build.
All fields are plain data so the whole thing is usable in const context.
#[non_exhaustive], so a future policy field is a semver-minor addition
rather than a breaking one. Construct with Params::new — a const fn,
since downstream #[non_exhaustive] rejects struct-literal construction
(functional-record-update included), leaving new as the only
construction path, and const context needs that path callable. The
non-breaking half rests on the fields being pub, not on new’s
parameter list: a future pub field would extend the struct but not
new’s positional signature, so existing Params::new(..) call sites
keep compiling and a consumer opts in with let mut p = Params::new(..); p.new_field = value; — post-construction assignment to a pub field,
which works outside this crate and in const context too.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.min_block: usizeThe minimum block size and the fundamental small-class alignment. Must
be a power of two. Every generated class is a multiple of it – see
SizeClasses::class_for’s # Preconditions for what that does and
does not guarantee about block addresses.
growth: (usize, usize)The geometric growth ratio as (num, den) — each class after the first
is round_up(ceil(prev * num / den), min_block), with a minimum step
of min_block so two adjacent classes never collide. (5, 4) is the
classic mimalloc 1.25× small spacing.
geo_count: usizeHow many classes the geometric progression contributes (starting at
min_block).
extras: &'a [usize]Explicit extra classes to merge into the geometric run — a strictly
increasing list, each entry a multiple of min_block and >= min_block (the builder sorted-merges them). All three preconditions
are machine-checked: a non-min_block-multiple entry, an entry
below min_block (rejects the degenerate 0 “class”), or a
non-strictly-increasing entry panics identically in const evaluation
(compile error) and at runtime in build_table. It also checks
disjointness from the geometric run at its own chokepoint (the merged
table must itself be strictly increasing). build_size2class keeps
the same check as defense-in-depth for a hand-built table that
bypasses build_table entirely. Typical uses: page-aligned classes,
an exact size the geometric run skips, a feature-gated medium tier.
Borrowed rather than owned because this is a no_std, zero-alloc
crate; in the usual const PARAMS: Params = Params::new(.., EXTRAS, ..) form 'a resolves to 'static, but nothing requires that.
huge_threshold: usizeThe “huge” policy threshold: SizeClasses::is_huge reports true for
a size >= this. Pure bookkeeping for the crate — the consumer decides
what “huge” means for its own segment policy (guard pages, eager
decommit, …).
Implementations§
Source§impl<'a> Params<'a>
impl<'a> Params<'a>
Sourcepub const fn new(
min_block: usize,
growth: (usize, usize),
geo_count: usize,
extras: &'a [usize],
huge_threshold: usize,
) -> Self
pub const fn new( min_block: usize, growth: (usize, usize), geo_count: usize, extras: &'a [usize], huge_threshold: usize, ) -> Self
Construct a Params from its component fields.
const fn, so it works in const PARAMS: Params = Params::new(..);
— the construction path for a #[non_exhaustive] type.