#[repr(C)]pub struct Heap { /* private fields */ }
Expand description
Comet heap. It stores all the required global data:
- GlobalAllocator instance
- Callbacks that are run before GC cycle
- Threshold and allocations of current GC cycle
- Number of deferred GC cycles
- Weak references
Implementations§
Source§impl Heap
impl Heap
Sourcepub fn for_each_cell(
&mut self,
callback: impl FnMut(*mut HeapObjectHeader),
weak_refs: impl FnMut(GcRef<WeakSlot>),
)
pub fn for_each_cell( &mut self, callback: impl FnMut(*mut HeapObjectHeader), weak_refs: impl FnMut(GcRef<WeakSlot>), )
This function will iterate through each object allocated in heap. Separate callbacks are used for weak refs and regular objects.
NOTE: callback for regular object might receive weak ref pointer in it too.
Sourcepub fn add_constraint(&mut self, constraint: impl MarkingConstraint + 'static)
pub fn add_constraint(&mut self, constraint: impl MarkingConstraint + 'static)
Adds GC constraint into constraints vector. Each constraint is ran before GC cycle.
Sourcepub fn add_core_constraints(&mut self)
pub fn add_core_constraints(&mut self)
Adds core GC constraints into constraint vector. For now it is just conservative stack marking constraint.
Sourcepub fn new(config: Config) -> Box<Heap>
pub fn new(config: Config) -> Box<Heap>
Creates new heap instance with configuration from config
.
Sourcepub fn collect_garbage(&mut self)
pub fn collect_garbage(&mut self)
Force collect garbage. If GC is deferred nothing will happen.
Sourcepub fn collect_if_necessary_or_defer(&mut self)
pub fn collect_if_necessary_or_defer(&mut self)
Collects garbage if necessary i.e allocates bytes are greater than threshold.
Sourcepub unsafe fn allocate_weak(&mut self, target: UntypedGcRef) -> WeakGcRef
pub unsafe fn allocate_weak(&mut self, target: UntypedGcRef) -> WeakGcRef
Allocate weak reference for specified GC pointer.
Sourcepub unsafe fn allocate_raw(
&mut self,
size: usize,
index: GCInfoIndex,
) -> Option<UntypedGcRef>
pub unsafe fn allocate_raw( &mut self, size: usize, index: GCInfoIndex, ) -> Option<UntypedGcRef>
Allocate “raw” memory. This memory is not initialized at all (except header part of UntypedGcRef).
size
should include size for object you’re allocating and additional bytes for HeapObjectHeader. If it is embedded in your struct as first field you do not have to include that.index
should be an index obtained by callingT::index()
on type that implements GCInfoTrait
This function returns none if allocation is failed.
Sourcepub unsafe fn allocate_raw_or_fail(
&mut self,
size: usize,
index: GCInfoIndex,
) -> UntypedGcRef
pub unsafe fn allocate_raw_or_fail( &mut self, size: usize, index: GCInfoIndex, ) -> UntypedGcRef
Same as Heap::allocate_raw except it will try to perform GC cycle and if GC does not free enough memory it will abort.