Struct toolshed::Arena
[−]
[src]
pub struct Arena { /* fields omitted */ }
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.
Methods
impl Arena
[src]
fn new() -> Self
[src]
Create a new arena with a single preallocated 64KiB page
fn alloc<'a, T: Sized + Copy>(&'a self, val: T) -> &'a T
[src]
Put the value onto the page of the arena and return a reference to it.
unsafe fn alloc_uninitialized<'a, T: Sized + Copy>(&'a self) -> &'a mut T
[src]
Allocate enough bytes for the type T
, then return a pointer to the memory.
Memory behind the pointer is uninitialized, can contain garbage and reading
from it is undefined behavior.
fn alloc_str<'a>(&'a self, val: &str) -> &'a str
[src]
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.
fn alloc_str_with_nul<'a>(&'a self, val: &str) -> *const u8
[src]
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.
fn alloc_string<'a>(&'a self, val: String) -> &'a str
[src]
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
.
Trait Implementations
impl Send for Arena
[src]
Akin to CopyCell
: Sync
is unsafe but Send
is totally fine!