Skip to main content

ScratchRegion

Struct ScratchRegion 

Source
pub struct ScratchRegion { /* private fields */ }
Expand description

Bump-allocated scratch space for temporary per-propagator data.

Propagators can request temporary f32 slices from scratch space for intermediate calculations (e.g. neighbourhood sums, gradient buffers). The scratch region is reset between propagator executions within a single tick — allocations do not persist across propagators or ticks.

§Example (conceptual)

let slice = scratch.alloc(100)?;
// use slice for intermediate computation
// scratch.reset() called by engine before next propagator

Implementations§

Source§

impl ScratchRegion

Source

pub fn new(initial_capacity: usize) -> Self

Create a new scratch region with the given initial capacity (in f32 elements).

Source

pub fn alloc(&mut self, len: usize) -> Option<&mut [f32]>

Allocate len f32 elements from scratch space.

Returns a zero-initialised mutable slice. Returns None if the scratch region cannot grow to accommodate the request (this should not happen in practice since Vec grows on demand; None is returned only if the system is out of memory).

Source

pub fn reset(&mut self)

Reset the scratch region for the next propagator.

This does NOT deallocate or zero the backing storage — it simply resets the bump pointer. The next alloc call will overwrite stale data with zeroes before returning.

Source

pub fn used(&self) -> usize

Number of f32 elements currently allocated.

Source

pub fn capacity(&self) -> usize

Total capacity of the backing storage in f32 elements.

Source

pub fn memory_bytes(&self) -> usize

Memory usage of the backing storage in bytes.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.