Skip to main content

GCDynamicReusableAllocator

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>

pub fn new(size: usize) -> DynamicReusableAllocator<T>

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>

§

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

Returns the number of allocated elements
§

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§

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.