[][src]Macro crndm::pool

macro_rules! pool {
    ($name:ident) => { ... };
}

This macro creates a new pool module and aliases for persistent types. It generates type BuddyAlloc which a persistent allocator type. It is recommended to alias the BuddyAlloc type for tidiness.

The aliased types are

Examples

To associate a single pool to the program, it is enough to define a pool type using this macro.

crndm::pool!(my_alloc);
use my_alloc::*;
 
type P = BuddyAlloc;
 
let _ = P::open_no_root("p.pool", O_CF).unwrap();
 
P::transaction(|j| {
    let temp = Pbox::new(10, j);
}).unwrap();

If multiple pools are needed, multiple pool modules can be defined and used.

use crndm::alloc::*;
 
crndm::pool!(pool1);
crndm::pool!(pool2);
 
type P1 = pool1::BuddyAlloc;
type P2 = pool2::BuddyAlloc;
 
let _ = P1::open_no_root("p1.pool", O_CF).unwrap();
let _ = P2::open_no_root("p2.pool", O_CF).unwrap();
 
P1::transaction(|j1| {
    let temp = pool1::Pbox::new(10, j1);
    P2::transaction(|j2| {
        let temp = pool2::Pbox::new(20, j2);
    }).unwrap();
}).unwrap();