Skip to main content

Heap

Struct Heap 

Source
pub struct Heap { /* private fields */ }
Expand description

A first-class heap (plan §5.14): Drop runs mi_heap_delete semantics (blocks migrate to the thread’s backing heap and stay valid) unless built with Heap::new_destroyable, where Drop releases every block at once. The destroyable form inherits C’s contract: callers must not touch its blocks after drop (a lifetime-carrying Allocator impl that makes this unrepresentable is the planned follow-up once allocator_api stabilizes).

Implementations§

Source§

impl Heap

Source

pub fn new() -> Heap

New heap; dropped ⇒ blocks migrate to the backing heap.

Source

pub fn new_destroyable() -> Heap

New heap; dropped ⇒ every allocation is released wholesale (arena-style teardown).

Source

pub fn alloc(&self, layout: Layout) -> Option<NonNull<u8>>

Allocate layout, borrowing the heap (so the block cannot outlive it).

Source

pub fn alloc_zeroed(&self, layout: Layout) -> Option<NonNull<u8>>

Zeroed variant of alloc.

Source

pub unsafe fn dealloc(&self, p: NonNull<u8>)

Free a block previously allocated from this heap.

§Safety

p came from this heap’s alloc methods and is freed exactly once.

Source

pub fn collect(&self)

Drain cross-thread frees and retire empty pages.

Trait Implementations§

Source§

impl Default for Heap

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Drop for Heap

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Heap

§

impl !Send for Heap

§

impl !Sync for Heap

§

impl !UnwindSafe for Heap

§

impl Freeze for Heap

§

impl Unpin for Heap

§

impl UnsafeUnpin 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> 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.