Struct comet::heap::Heap [−][src]
#[repr(C)]pub struct Heap { /* fields omitted */ }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
pub 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.
Adds GC constraint into constraints vector. Each constraint is ran before GC cycle.
Adds core GC constraints into constraint vector. For now it is just conservative stack marking constraint.
Creates new heap instance with configuration from config.
Force collect garbage. If GC is deferred nothing will happen.
Collects garbage if necessary i.e allocates bytes are greater than threshold.
Allocate weak reference for specified GC pointer.
pub 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).
sizeshould 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.indexshould be an index obtained by callingT::index()on type that implements GCInfoTrait
This function returns none if allocation is failed.
pub 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.