Skip to main content

Arena

Struct Arena 

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

A bump allocator over one fixed reservation, reset as a whole.

Implementations§

Source§

impl Arena

Source

pub fn with_capacity(bytes: usize) -> Arena

Reserve bytes up front. The buffer is taken from the global allocator once and held until the arena drops; nothing here allocates again.

Source

pub fn tagged(bytes: usize, tag: MemTag) -> Arena

As with_capacity, reporting the reservation under tag in host memory for as long as the arena lives. An arena’s whole cost is its reservation, so it can account for itself rather than making its owner do it.

Source

pub fn capacity(&self) -> usize

The reservation size in bytes.

Source

pub fn used(&self) -> usize

Bytes handed out since the last reset.

Source

pub fn remaining(&self) -> usize

Bytes still available before the next request is declined.

Source

pub fn peak(&self) -> usize

The most this arena has held between resets: what to size it from.

Source

pub fn overflows(&self) -> u32

Requests declined since the last clear_overflows. Non-zero means callers fell back to the heap and the reserve wants raising.

Source

pub fn clear_overflows(&self)

Reset the overflow counter.

Source

pub fn reset(&mut self)

Give back everything handed out. Taking &mut self is the safety argument: no allocation from this arena can still be borrowed.

Deliberately leaves peak and overflows alone: both describe the worst frame so far, which is what sizes the reserve, and a per-frame reset would erase exactly the evidence they exist to carry.

Source

pub fn alloc<T>(&self, value: T) -> Option<&mut T>
where T: Copy,

Move value into the arena. None when the arena is full, which is the caller’s cue to fall back to the heap rather than a failure.

Source

pub fn vec<T>(&self, capacity: usize) -> Option<ArenaVec<'_, T>>
where T: Copy,

An empty vector holding capacity elements’ worth of arena. Pushing past that capacity does not grow – the caller reserves the bound it knows.

Trait Implementations§

Source§

impl Drop for Arena

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
Source§

impl Send for Arena

Auto Trait Implementations§

§

impl !Freeze for Arena

§

impl !RefUnwindSafe for Arena

§

impl !Sync for Arena

§

impl Unpin for Arena

§

impl UnsafeUnpin for Arena

§

impl UnwindSafe for Arena

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 = !

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.