Skip to main content

FrameArena

Struct FrameArena 

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

A per-frame bump allocator for temporary render-path allocations.

FrameArena wraps bumpalo::Bump with a focused API for the common allocation patterns in the render pipeline: strings, slices, and single values. All allocations are invalidated on reset(), which should be called at frame boundaries.

§Capacity

The arena starts with an initial capacity and grows automatically when exhausted. Growth allocates new chunks from the global allocator but never moves existing allocations.

Implementations§

Source§

impl FrameArena

Source

pub fn new(capacity: usize) -> Self

Create a new arena with the given initial capacity in bytes.

§Panics

Panics if the system allocator cannot fulfill the initial allocation.

Source

pub fn with_default_capacity() -> Self

Create a new arena with the default capacity (256 KB).

Source

pub fn reset(&mut self)

Reset the arena, reclaiming all memory for reuse.

This is an O(1) operation. All previously allocated references are invalidated. The arena retains its allocated chunks for future allocations, avoiding repeated system allocator calls.

Source

pub fn alloc_str(&self, s: &str) -> &str

Allocate a string slice in the arena.

Returns a reference to the arena-allocated copy of s. The returned reference is valid until the next reset().

Source

pub fn alloc_slice<T: Copy>(&self, slice: &[T]) -> &[T]

Allocate a copy of a slice in the arena.

Returns a reference to the arena-allocated copy of slice. The returned reference is valid until the next reset().

Source

pub fn alloc_with<T, F: FnOnce() -> T>(&self, f: F) -> &mut T

Allocate a single value in the arena, constructed by f.

Returns a mutable reference to the arena-allocated value. The returned reference is valid until the next reset().

Source

pub fn alloc<T>(&self, val: T) -> &mut T

Allocate a single value in the arena.

Returns a mutable reference to the arena-allocated value. The returned reference is valid until the next reset().

Source

pub fn allocated_bytes(&self) -> usize

Returns the total bytes allocated in the arena (across all chunks).

Source

pub fn allocated_bytes_including_metadata(&self) -> usize

Returns the total bytes of unused capacity in the arena.

Source

pub fn as_bump(&self) -> &Bump

Returns a reference to the underlying Bump allocator.

Use this for advanced allocation patterns not covered by the convenience methods.

Trait Implementations§

Source§

impl Debug for FrameArena

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for FrameArena

Source§

fn default() -> Self

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

Auto Trait Implementations§

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.