scoped_allocator 0.1.4

A scoped linear allocator.
scoped_allocator-0.1.4 doesn't have any documentation.

Scoped Allocator

Build Status

This crate provides a scoped linear allocator. This is useful for reusing a block of memory for temporary allocations in a tight loop. Scopes can be nested and values allocated in a scope cannot be moved outside it.

struct Bomb(u8);
impl Drop for Bomb {
    fn drop(&mut self) {
        println!("Boom! {}", self.0);
    } 
}
// new allocator with a kilobyte of memory.
let alloc = ScopedAllocator::new(1024).unwrap();

alloc.scope(|inner| {
    let mut bombs = Vec::new();
    for i in 0..100 { bombs.push(inner.allocate_val(Bomb(i)).ok().unwrap())}

    // watch the bombs go off!
});

let my_int = alloc.allocate_val(23).ok().unwrap();
println!("My int: {}", *my_int);

Disclaimer: this crate leans heavily on unsafe code and nightly features and should not be used in production as it stands.