pub struct SearchScratch<S: Storage> { /* private fields */ }Expand description
Working memory of Plan::fits and
Plan::earliest_start, for callers that keep it outside the
stack.
With Fixed<N> storage it holds two change-point lists of 2 N
points and a set and a requirement list of N entries, 216 N + 128 bytes on 64-bit
targets: 58 KiB for N = 256. fits and earliest_start put it on the stack;
Plan::fits_with and
Plan::earliest_start_with borrow one instead, for
example from a static or a task’s own memory. Measured on x86-64 (release, frame sizes
from -Z emit-stack-sizes, confirmed by running in threads of shrinking stack): a search
over a FixedPlan<2, 1, 256> needs about 60 KiB of stack with the internal scratch and
fits in a 16 KiB thread stack with a borrowed one; its largest frame is the 2.4 KiB of the
change-point sort. Explaining a violation (first_violation) keeps its own per-activity
working list of 32 N bytes on the stack, about 16 KiB for N = 256.
§Examples
use resource_timeline::storage::{Fixed, FixedPlan};
use resource_timeline::{ActivityId, Demand, Impact, Plan, SearchScratch, Timeline, Window};
let mut plan = Plan::<FixedPlan<1, 0, 64>>::new_in();
let transmitter = plan.add_timeline(Timeline::claimable_in(0, 1, 64)?)?;
let downlink = [Demand::Level {
timeline: transmitter,
impact: Impact::Claim { start: 0, end: 8, amount: 1 },
}];
plan.place(ActivityId(1), 5, &downlink)?;
let mut scratch = SearchScratch::<Fixed<64>>::new();
let window = Window::new(0, 100)?;
assert_eq!(plan.earliest_start_with(&downlink, window, 1_000, &mut scratch)?, Some(13));