pub struct SolverArena { /* private fields */ }Expand description
A simple bump allocator for solver scratch buffers.
All allocations are contiguous within a single backing Vec<u8>.
The arena does not drop individual allocations; instead, call
reset to reclaim all space at once.
§Example
use ruvector_solver::arena::SolverArena;
let arena = SolverArena::with_capacity(1024);
let buf: &mut [f64] = arena.alloc_slice::<f64>(128);
assert_eq!(buf.len(), 128);
assert!(arena.bytes_used() >= 128 * std::mem::size_of::<f64>());
arena.reset();
assert_eq!(arena.bytes_used(), 0);Implementations§
Source§impl SolverArena
impl SolverArena
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Create a new arena with the given capacity in bytes.
The arena will not reallocate unless an allocation request exceeds the remaining capacity, in which case it grows by doubling.
Sourcepub fn alloc_slice<T: Copy + Default>(&self, len: usize) -> &mut [T]
pub fn alloc_slice<T: Copy + Default>(&self, len: usize) -> &mut [T]
Allocate a mutable slice of len elements of type T, zero-initialised.
§Panics
- Panics if
Thas alignment greater than 16 (an unusual case for solver numerics). - Panics if
size_of::<T>() * lenoverflowsusize(prevents integer overflow leading to undersized allocations).
Sourcepub fn reset(&self)
pub fn reset(&self)
Reset the arena, reclaiming all allocations.
This does not free the backing memory; it simply resets the bump pointer to zero. Subsequent allocations reuse the same buffer.
Sourcepub fn bytes_used(&self) -> usize
pub fn bytes_used(&self) -> usize
Number of bytes currently allocated (bump pointer position).
Trait Implementations§
impl Send for SolverArena
Auto Trait Implementations§
impl !Freeze for SolverArena
impl !RefUnwindSafe for SolverArena
impl !Sync for SolverArena
impl Unpin for SolverArena
impl UnsafeUnpin for SolverArena
impl UnwindSafe for SolverArena
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more