Struct block_allocator::Allocator [] [src]

pub struct Allocator<'a> { /* fields omitted */ }

Allocator Provides fixed-sized buffers from a pre-allocated arena specified at creation Current limitations: Max number of buffers it can produce is u32::MAX - 1 Multiple allocators may be in use at any time, but their buffers may not be used interchangibly :)

Note : This allocator will only produce blocks in sizes of powers of two. Any size requested that isn't a power of two will result in an error

Implementation This keeps track of the next available buffer in the slab using a Double CAS Treiber Stack Since Rust atomics don't actually support a double CAS yet, I am simulating it by CAS'ing on a single 64 bit value that is actually a [u32; 2], where the lower bits are the counter, and the higher order bits is the next offset

Example

use block_allocator::Allocator;

//reserve 100 usable blocks of size 512 (-4) bytes
let myalloc = Allocator::new(512, 100).unwrap();
let buf = myalloc.alloc().unwrap();

//do stuff

myalloc.free(buf);

Methods

impl<'a> Allocator<'a>
[src]

Constructs a new Block Allocator

Acquire the next free buffer from the allocator's slab

Free the buffer back into the allocator's slab

Acquire the next buffer as a raw std::u8 pointer from the allocator's slab

Free a raw (previously alloc'd pointer) back into the allocator's slab

Trait Implementations

impl<'a> Send for Allocator<'a>
[src]

impl<'a> Sync for Allocator<'a>
[src]