pub struct ObjectStore { /* private fields */ }Expand description
Thread-local storage for heap objects.
Uses a Vec<Option<HeapObject>> with a free-list for O(1) alloc/free.
A production implementation could use mmap’d regions for large heaps,
but the current design is correct and suitable for the interpreter.
Implementations§
Source§impl ObjectStore
impl ObjectStore
Sourcepub fn with_capacity(cap: usize) -> Self
pub fn with_capacity(cap: usize) -> Self
Create a new object store with pre-allocated capacity.
Sourcepub fn allocate(&mut self, obj: HeapObject) -> usize
pub fn allocate(&mut self, obj: HeapObject) -> usize
Allocate a new heap object and return its ID.
Sourcepub fn deallocate(&mut self, id: usize) -> Option<HeapObject>
pub fn deallocate(&mut self, id: usize) -> Option<HeapObject>
Deallocate a heap object by ID.
Sourcepub fn get(&self, id: usize) -> Option<&HeapObject>
pub fn get(&self, id: usize) -> Option<&HeapObject>
Get a reference to a heap object by ID.
Sourcepub fn get_mut(&mut self, id: usize) -> Option<&mut HeapObject>
pub fn get_mut(&mut self, id: usize) -> Option<&mut HeapObject>
Get a mutable reference to a heap object by ID.
Sourcepub fn stats(&self) -> &AllocationStats
pub fn stats(&self) -> &AllocationStats
Get allocation statistics.
Sourcepub fn live_count(&self) -> usize
pub fn live_count(&self) -> usize
Number of live objects.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ObjectStore
impl RefUnwindSafe for ObjectStore
impl Send for ObjectStore
impl Sync for ObjectStore
impl Unpin for ObjectStore
impl UnsafeUnpin for ObjectStore
impl UnwindSafe for ObjectStore
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