pub struct Allocator {}
Expand description
A memory allocator with buddy allocation mechanism
To define a new buddy allocator type as a memory pool, you may
use pool!()
macro.
Implementations
Trait Implementations
sourceimpl MemPoolTraits for Allocator
impl MemPoolTraits for Allocator
fn gen() -> u32
fn tx_gen() -> u32
sourceunsafe fn pre_alloc(size: usize) -> (*mut u8, u64, usize, usize)
unsafe fn pre_alloc(size: usize) -> (*mut u8, u64, usize, usize)
Prepares allocation without performing it Read more
sourceunsafe fn pre_dealloc(ptr: *mut u8, size: usize) -> usize
unsafe fn pre_dealloc(ptr: *mut u8, size: usize) -> usize
Prepares deallocation without performing it Read more
sourceunsafe fn log64(off: u64, val: u64, z: usize)
unsafe fn log64(off: u64, val: u64, z: usize)
Adds a low-level log to update as 64-bit obj
to val
when
perform()
is called. As an example, please see Log::set()
. Read more
sourceunsafe fn drop_on_failure(off: u64, len: usize, z: usize)
unsafe fn drop_on_failure(off: u64, len: usize, z: usize)
sourceunsafe fn prepare(z: usize)
unsafe fn prepare(z: usize)
In case of not using pre_alloc
or pre_dealloc
, starts a low-level
atomic section on a given zone. Read more
sourceunsafe fn journals_head() -> &'static u64
unsafe fn journals_head() -> &'static u64
Returns a reference to the offset of the first journal
sourceunsafe fn drop_journal(journal: &mut Journal)
unsafe fn drop_journal(journal: &mut Journal)
Drops a journal
from memory
sourceunsafe fn journals<T, F: Fn(&mut HashMap<ThreadId, (u64, i32)>) -> T>(f: F) -> T
unsafe fn journals<T, F: Fn(&mut HashMap<ThreadId, (u64, i32)>) -> T>(f: F) -> T
Runs a closure with a mutable reference to a thread->journal HashMap
unsafe fn dealloc_history() -> *mut HashSet<u64>
sourcefn open<'a, U: 'a + PSafe + RootObj<Self>>(
path: &str,
flags: u32
) -> Result<RootCell<'a, U, Self>>
fn open<'a, U: 'a + PSafe + RootObj<Self>>(
path: &str,
flags: u32
) -> Result<RootCell<'a, U, Self>>
Opens a pool and retrieves the root object Read more
sourcefn open_no_root(path: &str, flags: u32) -> Result<PoolGuard<Self>>
fn open_no_root(path: &str, flags: u32) -> Result<PoolGuard<Self>>
Opens a new pool without any root object. This function is for testing and is not useful in real applications as none of the allocated objects in persistent region is durable. The reason is that they are not reachable from a root object as it doesn’t exists. All objects can live only in the scope of a transaction. Read more
sourceunsafe fn close() -> Result<()>
unsafe fn close() -> Result<()>
Commits all changes and clears the logs for all threads Read more
fn stat_footprint() -> usize
sourcefn print_info()
fn print_info()
Prints memory information
sourceunsafe fn off_unchecked<T: ?Sized>(x: *const T) -> u64
unsafe fn off_unchecked<T: ?Sized>(x: *const T) -> u64
Translates raw pointers to memory offsets Read more
sourceunsafe fn get_unchecked<'a, T: 'a + ?Sized>(off: u64) -> &'a T
unsafe fn get_unchecked<'a, T: 'a + ?Sized>(off: u64) -> &'a T
Acquires a reference pointer to the object Read more
sourceunsafe fn get_mut_unchecked<'a, T: 'a + ?Sized>(off: u64) -> &'a mut T
unsafe fn get_mut_unchecked<'a, T: 'a + ?Sized>(off: u64) -> &'a mut T
Acquires a mutable reference to the object Read more
sourceunsafe fn deref_slice_unchecked<'a, T: 'a>(off: u64, len: usize) -> &'a [T]ⓘNotable traits for &'_ [u8]impl<'_> Read for &'_ [u8]impl<'_> Write for &'_ mut [u8]
unsafe fn deref_slice_unchecked<'a, T: 'a>(off: u64, len: usize) -> &'a [T]ⓘNotable traits for &'_ [u8]impl<'_> Read for &'_ [u8]impl<'_> Write for &'_ mut [u8]
Acquires a reference to the slice Read more
sourceunsafe fn deref_slice_unchecked_mut<'a, T: 'a>(
off: u64,
len: usize
) -> &'a mut [T]ⓘNotable traits for &'_ [u8]impl<'_> Read for &'_ [u8]impl<'_> Write for &'_ mut [u8]
unsafe fn deref_slice_unchecked_mut<'a, T: 'a>(
off: u64,
len: usize
) -> &'a mut [T]ⓘNotable traits for &'_ [u8]impl<'_> Read for &'_ [u8]impl<'_> Write for &'_ mut [u8]
Acquires a mutable reference to the slice Read more
sourceunsafe fn deref_mut<'a, T: 'a>(off: u64) -> Result<&'a mut T>
unsafe fn deref_mut<'a, T: 'a>(off: u64) -> Result<&'a mut T>
Acquires a mutable reference pointer to the object
sourcefn contains(addr: u64) -> bool
fn contains(addr: u64) -> bool
Checks if addr
is in the valid address range if this allocator Read more
sourceunsafe fn alloc(size: usize) -> (*mut u8, u64, usize)
unsafe fn alloc(size: usize) -> (*mut u8, u64, usize)
Allocate memory as described by the given size
. Read more
sourceunsafe fn dealloc(ptr: *mut u8, size: usize)
unsafe fn dealloc(ptr: *mut u8, size: usize)
Deallocate the block of memory at the given ptr
pointer with the
given size
. Read more
sourceunsafe fn alloc_zeroed(size: usize) -> *mut u8
unsafe fn alloc_zeroed(size: usize) -> *mut u8
Behaves like alloc
, but also ensures that the contents
are set to zero before being returned. Read more
sourceunsafe fn new<'a, T: PSafe + 'a>(x: T, j: &Journal<Self>) -> &'a mut T where
Self: MemPool,
unsafe fn new<'a, T: PSafe + 'a>(x: T, j: &Journal<Self>) -> &'a mut T where
Self: MemPool,
Allocates new memory and then places x
into it with DropOnFailure
log
sourceunsafe fn new_slice<'a, T: PSafe + 'a>(
x: &'a [T],
journal: &Journal<Self>
) -> &'a mut [T]ⓘNotable traits for &'_ [u8]impl<'_> Read for &'_ [u8]impl<'_> Write for &'_ mut [u8]
where
Self: MemPool,
unsafe fn new_slice<'a, T: PSafe + 'a>(
x: &'a [T],
journal: &Journal<Self>
) -> &'a mut [T]ⓘNotable traits for &'_ [u8]impl<'_> Read for &'_ [u8]impl<'_> Write for &'_ mut [u8]
where
Self: MemPool,
Allocates a new slice and then places x
into it with DropOnAbort
log
sourceunsafe fn new_copy<'a, T: 'a>(x: &T, j: &Journal<Self>) -> &'a mut T where
T: ?Sized,
Self: MemPool,
unsafe fn new_copy<'a, T: 'a>(x: &T, j: &Journal<Self>) -> &'a mut T where
T: ?Sized,
Self: MemPool,
Allocates new memory and then copies x
into it with DropOnFailure
log
sourceunsafe fn new_copy_slice<'a, T: 'a>(x: &[T], j: &Journal<Self>) -> &'a mut [T]ⓘNotable traits for &'_ [u8]impl<'_> Read for &'_ [u8]impl<'_> Write for &'_ mut [u8]
where
Self: MemPool,
unsafe fn new_copy_slice<'a, T: 'a>(x: &[T], j: &Journal<Self>) -> &'a mut [T]ⓘNotable traits for &'_ [u8]impl<'_> Read for &'_ [u8]impl<'_> Write for &'_ mut [u8]
where
Self: MemPool,
Allocates new memory and then copies x
into it with DropOnFailure
log
sourceunsafe fn atomic_new<'a, T: 'a>(x: T) -> (&'a mut T, u64, usize, usize)
unsafe fn atomic_new<'a, T: 'a>(x: T) -> (&'a mut T, u64, usize, usize)
Allocates new memory and then places x
into it without realizing the allocation
sourceunsafe fn atomic_new_slice<'a, T: 'a + PSafe>(
x: &'a [T]
) -> (&'a mut [T], u64, usize, usize)
unsafe fn atomic_new_slice<'a, T: 'a + PSafe>(
x: &'a [T]
) -> (&'a mut [T], u64, usize, usize)
Allocates new memory and then places x
into it without realizing the allocation
sourceunsafe fn new_uninit<'a, T: PSafe + 'a>(j: &Journal<Self>) -> &'a mut T where
Self: MemPool,
unsafe fn new_uninit<'a, T: PSafe + 'a>(j: &Journal<Self>) -> &'a mut T where
Self: MemPool,
Allocates new memory without copying data
sourceunsafe fn new_uninit_for_layout(size: usize, journal: &Journal<Self>) -> *mut u8 where
Self: MemPool,
unsafe fn new_uninit_for_layout(size: usize, journal: &Journal<Self>) -> *mut u8 where
Self: MemPool,
Allocates new memory without copying data
sourceunsafe fn atomic_new_uninit<'a, T: 'a>() -> (&'a mut T, u64, usize, usize)
unsafe fn atomic_new_uninit<'a, T: 'a>() -> (&'a mut T, u64, usize, usize)
Allocates new memory without copying data and realizing the allocation
sourceunsafe fn alloc_for_value<'a, T: ?Sized>(x: &T) -> &'a mut T
unsafe fn alloc_for_value<'a, T: ?Sized>(x: &T) -> &'a mut T
Allocates new memory for value x
sourceunsafe fn free<'a, T: PSafe + ?Sized>(x: &mut T) where
Self: MemPool,
unsafe fn free<'a, T: PSafe + ?Sized>(x: &mut T) where
Self: MemPool,
Creates a DropOnCommit
log for the value x
sourceunsafe fn free_slice<'a, T: PSafe>(x: &[T]) where
Self: MemPool,
unsafe fn free_slice<'a, T: PSafe>(x: &[T]) where
Self: MemPool,
Creates a DropOnCommit
log for the value x
sourceunsafe fn free_nolog<'a, T: ?Sized>(x: &T)
unsafe fn free_nolog<'a, T: ?Sized>(x: &T)
Frees the allocation for value x
immediately
sourceunsafe fn commit() where
Self: MemPool,
unsafe fn commit() where
Self: MemPool,
Commits all changes and clears the logs for one thread Read more
sourceunsafe fn commit_no_clear() where
Self: MemPool,
unsafe fn commit_no_clear() where
Self: MemPool,
Commits all changes without clearing the logs Read more
sourceunsafe fn rollback() -> bool where
Self: MemPool,
unsafe fn rollback() -> bool where
Self: MemPool,
Discards all changes and clears the logs Read more
sourceunsafe fn rollback_no_clear() where
Self: MemPool,
unsafe fn rollback_no_clear() where
Self: MemPool,
Discards all changes without clearing the logs Read more
sourcefn transaction<T, F: FnOnce(&'static Journal<Self>) -> T>(body: F) -> Result<T> where
F: TxInSafe + UnwindSafe,
T: TxOutSafe,
Self: MemPool,
fn transaction<T, F: FnOnce(&'static Journal<Self>) -> T>(body: F) -> Result<T> where
F: TxInSafe + UnwindSafe,
T: TxOutSafe,
Self: MemPool,
Executes commands atomically with respect to system crashes Read more
impl Copy for Allocator
impl MemPool for Allocator
Auto Trait Implementations
impl LooseTxInUnsafe for Allocator
impl PSafe for Allocator
impl PSend for Allocator
impl RefUnwindSafe for Allocator
impl Send for Allocator
impl Sync for Allocator
impl TxInSafe for Allocator
impl TxOutSafe for Allocator
impl Unpin for Allocator
impl UnwindSafe for Allocator
impl VSafe for Allocator
Blanket Implementations
sourceimpl<T, P> Allocatable<T, P> for T where
T: Default,
P: MemPool,
impl<T, P> Allocatable<T, P> for T where
T: Default,
P: MemPool,
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more