pub struct Arena { /* private fields */ }
Expand description
An arena implementation that uses preallocated 64KiB pages for all allocations. If a new allocation were to be pushed over the the boundaries of the page, a new page is internally allocated first, thus this version of the arena can never run out of memory unless the process runs out of heap altogether.
Allocating a type larger than the page size will result in a new heap allocation just for that type separate from the page mechanism.
Implementations
sourceimpl Arena
impl Arena
sourcepub fn alloc<'arena, T: Sized + Copy>(&'arena self, value: T) -> &'arena mut T
pub fn alloc<'arena, T: Sized + Copy>(&'arena self, value: T) -> &'arena mut T
Put the value onto the page of the arena and return a reference to it.
sourcepub fn alloc_uninitialized<'arena, T: Sized + Copy>(
&'arena self
) -> Uninitialized<'arena, T>
pub fn alloc_uninitialized<'arena, T: Sized + Copy>(
&'arena self
) -> Uninitialized<'arena, T>
Allocate enough bytes for the type T
, then return an Uninitialized
pointer to the memory.
sourcepub fn alloc_slice<'arena, T: Copy>(&'arena self, val: &[T]) -> &'arena [T] ⓘ
pub fn alloc_slice<'arena, T: Copy>(&'arena self, val: &[T]) -> &'arena [T] ⓘ
Allocate a slice of T
slice onto the arena and return a reference to it.
This is useful when the original slice has an undefined lifetime.
Note: static slices (&'static [T]
) can be safely used in place of arena-bound
slices without having to go through this method.
sourcepub fn alloc_vec<'arena, T: Copy>(&'arena self, val: Vec<T>) -> &'arena [T] ⓘ
pub fn alloc_vec<'arena, T: Copy>(&'arena self, val: Vec<T>) -> &'arena [T] ⓘ
Put a Vec<T>
on the arena without reallocating.
sourcepub fn alloc_cow<'input, 'arena, T>(
&'arena self,
vals: Cow<'input, [T]>
) -> &'arena [T] ⓘwhere
T: Sized + Copy + 'input,
pub fn alloc_cow<'input, 'arena, T>(
&'arena self,
vals: Cow<'input, [T]>
) -> &'arena [T] ⓘwhere
T: Sized + Copy + 'input,
Allocate many items at once, avoid allocation for owned values.
sourcepub fn alloc_str<'arena>(&'arena self, val: &str) -> &'arena str
pub fn alloc_str<'arena>(&'arena self, val: &str) -> &'arena str
Allocate an &str
slice onto the arena and return a reference to it. This is
useful when the original slice has an undefined lifetime.
Note: static slices (&'static str
) can be safely used in place of arena-bound
slices without having to go through this method.
sourcepub fn alloc_nul_term_str<'arena>(&'arena self, val: &str) -> NulTermStr<'_>
pub fn alloc_nul_term_str<'arena>(&'arena self, val: &str) -> NulTermStr<'_>
Allocate an &str
slice onto the arena as null terminated C-style string.
No checks are performed on the source and whether or not it already contains
any nul bytes. While this does not create any memory issues, it assumes that
the reader of the source can deal with malformed source.
sourcepub fn alloc_string<'arena>(&'arena self, val: String) -> &'arena str
pub fn alloc_string<'arena>(&'arena self, val: String) -> &'arena str
Pushes the String
as it’s own page onto the arena and returns a reference to it.
This does not copy or reallocate the original String
.