Skip to main content

BumpAllocator

Struct BumpAllocator 

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

A fast bump allocator for temporary allocations.

Allocates memory by simply incrementing a pointer. All allocated memory is freed at once when the allocator is reset or dropped.

This allocator is not thread-safe and should only be used from a single thread.

Implementations§

Source§

impl BumpAllocator

Source

pub fn new() -> Self

Creates a new bump allocator.

Source

pub fn with_capacity(capacity: usize) -> Self

Creates a new bump allocator with the given initial capacity.

Source

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

Allocates memory for a value of type T and initializes it.

Source

pub fn alloc_slice_copy<T: Copy>(&self, values: &[T]) -> &mut [T]

Allocates memory for a slice and copies the values.

Source

pub fn alloc_slice_clone<T: Clone>(&self, values: &[T]) -> &mut [T]

Allocates memory for a slice and clones the values.

Source

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

Allocates memory for a string and returns a mutable reference.

Source

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

Allocates raw bytes with the given layout.

Source

pub fn reset(&mut self)

Resets the allocator, freeing all allocated memory.

This is very fast - it just resets the internal pointer.

Source

pub fn allocated_bytes(&self) -> usize

Returns the number of bytes currently allocated.

Source

pub fn allocation_count(&self) -> usize

Returns the number of allocations made.

Source

pub fn chunk_count(&mut self) -> usize

Returns the number of chunks in use.

Trait Implementations§

Source§

impl Default for BumpAllocator

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.