Struct GCDynamicReusableAllocator
pub struct GCDynamicReusableAllocator<T: Default> {
object_memory: RwLock<Vec<GCArc<T>>>,
empty_indexes: Arc<RwLock<VecDeque<usize>>>,
}Expand description
A dynamic reusable memory allocator which uses a RwLock<VecDeque> to store the empty available memory locations. It will attempt to reuse any memory blocks already allocated, otherwise it will do an additional allocation.
Uses a VecDeque to keep track of the empty indexes and all memory blocks have a reference to it.
Fields§
§object_memory: RwLock<Vec<GCArc<T>>>§empty_indexes: Arc<RwLock<VecDeque<usize>>>Implementations§
§impl<T: Default> DynamicReusableAllocator<T>
impl<T: Default> DynamicReusableAllocator<T>
pub fn new(size: usize) -> DynamicReusableAllocator<T>
pub unsafe fn clear(&self)
pub unsafe fn clear(&self)
Clears the memory allocator and resets it to the initial state The caller has to ensure that there are no more references to the memory blocks. This function should only be used for testing purposes.
§Safety
This will clear all the memory blocks available, if there are still references to them, it is considered undefined behavior.
Trait Implementations§
§impl<T: Default + 'static> GCAllocator<T> for DynamicReusableAllocator<T>
impl<T: Default + 'static> GCAllocator<T> for DynamicReusableAllocator<T>
§fn add(&self, element: T) -> GCArc<T>
fn add(&self, element: T) -> GCArc<T>
Adds a new element to the allocator, if the allocator is full it will allocate a new block of memory.
§fn allocated_count(&self) -> usize
fn allocated_count(&self) -> usize
Returns the number of allocated elements
§fn available_allocated_count(&self) -> usize
fn available_allocated_count(&self) -> usize
Returns the number of available allocated elements
impl<T: Default> Send for DynamicReusableAllocator<T>
impl<T: Default> Sync for DynamicReusableAllocator<T>
Auto Trait Implementations§
impl<T> !Freeze for DynamicReusableAllocator<T>
impl<T> RefUnwindSafe for DynamicReusableAllocator<T>
impl<T> Unpin for DynamicReusableAllocator<T>
impl<T> UnsafeUnpin for DynamicReusableAllocator<T>
impl<T> UnwindSafe for DynamicReusableAllocator<T>
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