pub struct BuddyBlock {
pub ptr: *mut u8,
pub size: usize,
pub order: usize,
pub is_allocated: bool,
pub allocated_at: Option<Instant>,
pub last_accessed: Option<Instant>,
pub access_count: u64,
}Expand description
Buddy block representation
Fields§
§ptr: *mut u8Block address
size: usizeBlock size (always power of 2)
order: usizeBlock order (log2 of size / min_block_size)
is_allocated: boolWhether block is allocated
allocated_at: Option<Instant>Allocation timestamp
last_accessed: Option<Instant>Last access timestamp
access_count: u64Access count
Implementations§
Source§impl BuddyBlock
impl BuddyBlock
pub fn new(ptr: *mut u8, size: usize, order: usize) -> Self
pub fn allocate(&mut self)
pub fn deallocate(&mut self)
pub fn access(&mut self)
Sourcepub fn get_buddy_address(&self, base_ptr: *mut u8) -> *mut u8
pub fn get_buddy_address(&self, base_ptr: *mut u8) -> *mut u8
Get buddy address for this block.
The classic buddy-system XOR trick (offset ^ size) only identifies
the true buddy when offset is measured relative to a base every
block shares. base_ptr (the allocator’s arena base, e.g.
BuddyAllocator::base_ptr) must be that shared base: XOR-ing the
raw absolute pointer would only coincidentally find the real buddy,
since a real heap allocation’s address is not generally a multiple
of the arena’s total size.
Sourcepub fn is_buddy_of(&self, other: &BuddyBlock, base_ptr: *mut u8) -> bool
pub fn is_buddy_of(&self, other: &BuddyBlock, base_ptr: *mut u8) -> bool
Check if two blocks are buddies, relative to the allocator’s
base_ptr (see Self::get_buddy_address).
Trait Implementations§
Source§impl Clone for BuddyBlock
impl Clone for BuddyBlock
Source§fn clone(&self) -> BuddyBlock
fn clone(&self) -> BuddyBlock
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl !Send for BuddyBlock
impl !Sync for BuddyBlock
impl Freeze for BuddyBlock
impl RefUnwindSafe for BuddyBlock
impl Unpin for BuddyBlock
impl UnsafeUnpin for BuddyBlock
impl UnwindSafe for BuddyBlock
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more