Struct any_arena::AnyArena [] [src]

pub struct AnyArena<'longer_than_self> { /* fields omitted */ }

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

This arena uses RawVec<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<'longer_than_self> AnyArena<'longer_than_self>
[src]

Allocates a new AnyArena with 32 bytes preallocated.

Allocates a new AnyArena with initial_size bytes preallocated.

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

Allocates a slice of bytes of requested length. The bytes are not guaranteed to be zero if the arena has previously been cleared.

Panics

Panics if the requested length is too large and causes overflow.

Clears the arena. Deallocates all but the longest chunk which may be reused.

Trait Implementations

impl<'longer_than_self> Drop for AnyArena<'longer_than_self>
[src]

A method called when the value goes out of scope. Read more