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) -> *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_zero_end<'a>(&'a self, val: &str) -> *const u8
[src]
Allocate an &str
slice onto the arena with an extra null byte at the end.
Can be useful for C-style byte parsers where a null byte is not expected in
a well formatted string.
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
.
unsafe fn clear(&self)
[src]
Resets the pointer to the current page of the arena.
Using this method is an extremely bad idea!
The only case where the use of this method would be justified is in benchmarks where creation of a structure on the arena is to be tested without the cost of re-creating the arena itself on every iteration.