Struct toolshed::Arena

source ·
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

Create a new arena with a single preallocated 64KiB page.

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

Allocate enough bytes for the type T, then return an Uninitialized pointer to the memory.

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.

Put a Vec<T> on the arena without reallocating.

Allocate many items at once, avoid allocation for owned values.

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.

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.

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

Akin to CopyCell: Sync is unsafe but Send is totally fine!

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.