Crate allocators [−] [src]
Custom memory allocators and utilities for using them.
Examples
#![feature(placement_in_syntax)] use std::io; use allocators::{Allocator, Scoped, BlockOwner, FreeList, Proxy}; #[derive(Debug)] struct Bomb(u8); impl Drop for Bomb { fn drop(&mut self) { println!("Boom! {}", self.0); } } // new scoped allocator with 4 kilobytes of memory. let alloc = Scoped::new(4 * 1024).unwrap(); alloc.scope(|inner| { let mut bombs = Vec::new(); // allocate makes the value on the stack first. for i in 0..100 { bombs.push(inner.allocate(Bomb(i)).unwrap())} // there's also in-place allocation! let bomb_101 = in inner.make_place().unwrap() { Bomb(101) }; // watch the bombs go off! }); // You can make allocators backed by other allocators. { let secondary_alloc = FreeList::new_from(&alloc, 128, 8).unwrap(); let mut val = secondary_alloc.allocate(0i32).unwrap(); *val = 1; }
Reexports
pub use composable::*; |
pub use freelist::FreeList; |
pub use scoped::Scoped; |
Modules
composable |
This module contains some composable building blocks to build allocator chains. |
freelist |
A Free List allocator. |
scoped |
A scoped linear allocator. This is something of a cross between a stack allocator and a traditional linear allocator. |
Structs
AllocBox |
An item allocated by a custom allocator. |
Block |
A block of memory created by an allocator. |
HeapAllocator |
Allocator stub that just forwards to heap allocation.
It is recommended to use the |
Place |
A place for allocating into.
This is only used for in-place allocation,
e.g. |
Enums
Error |
Errors that can occur while creating an allocator or allocating from it. |
Constants
HEAP |
Traits
Allocator |
A custom memory allocator. |
BlockOwner |
An allocator that knows which blocks have been issued by it. |