macro_rules! pool {
($mod:ident, $name:ident) => { ... };
($mod:ident) => { ... };
}
Expand description
This macro creates a new pool module and aliases for persistent types. It
generates type Allocator
which a persistent allocator type. It is
recommended to alias the Allocator
type for tidiness.
The aliased types are
Pbox<T>
=corundum::boxed::Pbox
<T,
Allocator
>
Prc<T>
=corundum::prc::Prc
<T,
Allocator
>
Parc<T>
=corundum::sync::Parc
<T,
Allocator
>
PMutex<T>
=corundum::sync::PMutex
<T,
Allocator
>
PCell<T>
=corundum::cell::PCell
<T,
Allocator
>
PRefCell<T>
=corundum::cell::PRefCell
<T,
Allocator
>
VCell<T>
=corundum::cell::VCell
<T,
Allocator
>
TCell<T>
=corundum::cell::TCell
<T,
Allocator
>
PVec<T>
=corundum::vec::Vec
<T,
Allocator
>
PString
=corundum::str::String
<
Allocator
>
Examples
To associate a single pool to the program, it is enough to define a pool type using this macro.
corundum::pool!(my_alloc);
use my_alloc::*;
type P = Allocator;
let _pool = 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 corundum::alloc::heap::*;
corundum::pool!(pool1);
corundum::pool!(pool2);
type P1 = pool1::Allocator;
type P2 = pool2::Allocator;
let _p1 = P1::open_no_root("p1.pool", O_CF).unwrap();
let _p2 = 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();