Struct Heap

Source
#[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

Source

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.

Source

pub fn add_constraint(&mut self, constraint: impl MarkingConstraint + 'static)

Adds GC constraint into constraints vector. Each constraint is ran before GC cycle.

Source

pub fn add_core_constraints(&mut self)

Adds core GC constraints into constraint vector. For now it is just conservative stack marking constraint.

Source

pub fn new(config: Config) -> Box<Heap>

Creates new heap instance with configuration from config.

Source

pub fn collect_garbage(&mut self)

Force collect garbage. If GC is deferred nothing will happen.

Source

pub fn collect_if_necessary_or_defer(&mut self)

Collects garbage if necessary i.e allocates bytes are greater than threshold.

Source

pub unsafe fn allocate_weak(&mut self, target: UntypedGcRef) -> WeakGcRef

Allocate weak reference for specified GC pointer.

Source

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 calling T::index() on type that implements GCInfoTrait

This function returns none if allocation is failed.

Source

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.

Trait Implementations§

Source§

impl Drop for Heap

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl !Freeze for Heap

§

impl !RefUnwindSafe for Heap

§

impl !Send for Heap

§

impl !Sync for Heap

§

impl Unpin for Heap

§

impl !UnwindSafe for Heap

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> Any for T
where T: Any,

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.