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]

[src]

Create a new arena with a single preallocated 64KiB page

[src]

Put the value onto the page of the arena and return a reference to it.

[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.

[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.

[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.

[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.

[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.