Skip to main content

Crate gc_memory

Crate gc_memory 

Expand description

A dynamic reusable memory allocator, using the heap. It works similar to Arc but once all references are dropped, the memory can be reused. To accomplish this, the allocator wraps each objects into a container with a reference back to the allocator, additionally the allocator also contains a reference to every allocated object. Once all external references to that object are dropped, the block of memory will be automatically set as available for reuse.

Currently every allocation will exist while there are references to it, either external references or from the allocator itself. Currently the only allocator implemented is GCDynamicReusableAllocator.

§Usage:

use crate::gc_memory::GCAllocator;
use gc_memory::{GCDynamicReusableAllocator, GCArc};

let allocator = GCDynamicReusableAllocator::<i32>::new(0);
let arc: GCArc<i32> = allocator.add(10);
let arc2: GCArc<i32> = arc.clone();

Modules§

dynamic_allocator 🔒

Structs§

GCArc
A reference counted smart pointer that allows shared ownership of a value of type T, allocated with a crate::GCAllocator.
GCDynamicReusableAllocator
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.

Traits§

GCAllocator
Trait that defines the basic operations of a GCAllocator and should be implemented by every allocator.