Struct arena::ArenaUnstable [-] [+] [src]

pub struct Arena<'longer_than_self> {
    // some fields omitted
}

A slower reflection-based arena that can allocate objects of any type.

This arena uses Vec<u8> as a backing store to allocate objects from. For each allocated object, the arena stores a pointer to the type descriptor followed by the object (potentially with alignment padding after each element). When the arena is destroyed, it iterates through all of its chunks, and uses the tydesc information to trace through the objects, calling the destructors on them. One subtle point that needs to be addressed is how to handle panics while running the user provided initializer function. It is important to not run the destructor on uninitialized objects, but how to detect them is somewhat subtle. Since alloc() can be invoked recursively, it is not sufficient to simply exclude the most recent object. To solve this without requiring extra space, we use the low order bit of the tydesc pointer to encode whether the object it describes has been fully initialized.

As an optimization, objects with destructors are stored in different chunks than objects without destructors. This reduces overhead when initializing plain-old-data (Copy types) and means we don't need to waste time running their destructors.

Methods

impl<'a> Arena<'a>

fn new() -> Arena<'a>

Allocates a new Arena with 32 bytes preallocated.

fn new_with_size(initial_size: usize) -> Arena<'a>

Allocates a new Arena with initial_size bytes preallocated.

impl<'longer_than_self> Arena<'longer_than_self>

fn alloc<T: 'longer_than_self, F>(&self, op: F) -> &mut T where F: FnOnce() -> T

Allocates a new item in the arena, using op to initialize the value, and returns a reference to it.

Trait Implementations

impl<'longer_than_self> Drop for Arena<'longer_than_self>

fn drop(&mut self)