[][src]Struct kioku::Arena

pub struct Arena { /* fields omitted */ }

A growable memory arena for Copy types.

The arena works by allocating memory in blocks of slowly increasing size. It doles out memory from the current block until an amount of memory is requested that doesn't fit in the remainder of the current block, and then allocates a new block.

Additionally, it attempts to minimize wasted space through some heuristics. By default, it tries to keep memory waste within the arena below 10%.

Methods

impl Arena[src]

pub fn new() -> Arena[src]

Create a new arena, with default minimum block size.

pub fn with_min_block_size(min_block_size: usize) -> Arena[src]

Create a new arena, with a specified minimum block size.

pub fn with_settings(
    min_block_size: usize,
    max_waste_percentage: usize
) -> Arena
[src]

Create a new arena, with a specified minimum block size and maximum waste percentage.

pub fn stats(&self) -> (usize, usize, usize)[src]

Returns statistics about the current usage as a tuple: (space occupied, space allocated, block count, large block count)

Space occupied is the amount of real memory that the Arena is taking up (not counting book keeping).

Space allocated is the amount of the occupied space that is actually used. In other words, it is the sum of the all the allocation requests made to the arena by client code.

Block count is the number of blocks that have been allocated.

pub unsafe fn free_all_and_reset(&self)[src]

Frees all memory currently allocated by the arena, resetting itself to start fresh.

CAUTION: this is unsafe because it does NOT ensure that all references to the data are gone, so this can potentially lead to dangling references.

pub fn alloc<T: Copy>(&self, value: T) -> &mut T[src]

Allocates memory for and initializes a type T, returning a mutable reference to it.

pub fn alloc_with_alignment<T: Copy>(&self, value: T, align: usize) -> &mut T[src]

Allocates memory for and initializes a type T, returning a mutable reference to it.

Additionally, the allocation will be made with the given byte alignment or the type's inherent alignment, whichever is greater.

pub fn alloc_uninitialized<T: Copy>(&self) -> &mut MaybeUninit<T>[src]

Allocates memory for a type T, returning a mutable reference to it.

CAUTION: the memory returned is uninitialized. Make sure to initalize before using!

pub fn alloc_uninitialized_with_alignment<T: Copy>(
    &self,
    align: usize
) -> &mut MaybeUninit<T>
[src]

Allocates memory for a type T, returning a mutable reference to it.

Additionally, the allocation will be made with the given byte alignment or the type's inherent alignment, whichever is greater.

CAUTION: the memory returned is uninitialized. Make sure to initalize before using!

pub fn alloc_array<T: Copy>(&self, len: usize, value: T) -> &mut [T][src]

Allocates memory for len values of type T, returning a mutable slice to it. All elements are initialized to the given value.

pub fn alloc_array_with_alignment<T: Copy>(
    &self,
    len: usize,
    value: T,
    align: usize
) -> &mut [T]
[src]

Allocates memory for len values of type T, returning a mutable slice to it. All elements are initialized to the given value.

Additionally, the allocation will be made with the given byte alignment or the type's inherent alignment, whichever is greater.

pub fn copy_slice<T: Copy>(&self, other: &[T]) -> &mut [T][src]

Allocates and initializes memory to duplicate the given slice, returning a mutable slice to the new copy.

pub fn copy_slice_with_alignment<T: Copy>(
    &self,
    other: &[T],
    align: usize
) -> &mut [T]
[src]

Allocates and initializes memory to duplicate the given slice, returning a mutable slice to the new copy.

Additionally, the allocation will be made with the given byte alignment or the type's inherent alignment, whichever is greater.

pub fn alloc_array_uninitialized<T: Copy>(
    &self,
    len: usize
) -> &mut [MaybeUninit<T>]
[src]

Allocates memory for len values of type T, returning a mutable slice to it.

CAUTION: the memory returned is uninitialized. Make sure to initalize before using!

pub fn alloc_array_uninitialized_with_alignment<T: Copy>(
    &self,
    len: usize,
    align: usize
) -> &mut [MaybeUninit<T>]
[src]

Allocates memory for len values of type T, returning a mutable slice to it.

Additionally, the allocation will be made with the given byte alignment or the type's inherent alignment, whichever is greater.

CAUTION: the memory returned is uninitialized. Make sure to initalize before using!

Trait Implementations

impl Debug for Arena[src]

impl Default for Arena[src]

Auto Trait Implementations

impl !RefUnwindSafe for Arena

impl Send for Arena

impl !Sync for Arena

impl Unpin for Arena

impl UnwindSafe for Arena

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.