pub struct BuddyAllocator { /* private fields */ }Expand description
Buddy system allocator implementation
Implementations§
Source§impl BuddyAllocator
impl BuddyAllocator
Sourcepub fn new(
base_ptr: *mut u8,
total_size: usize,
config: BuddyConfig,
) -> Result<Self, BuddyError>
pub fn new( base_ptr: *mut u8, total_size: usize, config: BuddyConfig, ) -> Result<Self, BuddyError>
Create a new buddy allocator
Sourcepub fn allocate(&mut self, size: usize) -> Result<*mut u8, BuddyError>
pub fn allocate(&mut self, size: usize) -> Result<*mut u8, BuddyError>
Allocate memory of specified size
Sourcepub fn deallocate(&mut self, ptr: *mut u8) -> Result<(), BuddyError>
pub fn deallocate(&mut self, ptr: *mut u8) -> Result<(), BuddyError>
Deallocate memory at specified pointer
Sourcepub fn calculate_fragmentation(&self) -> f64
pub fn calculate_fragmentation(&self) -> f64
Calculate current fragmentation level
Sourcepub fn defragment(&mut self) -> usize
pub fn defragment(&mut self) -> usize
Perform defragmentation by coalescing free blocks
Sourcepub fn get_stats(&self) -> &BuddyStats
pub fn get_stats(&self) -> &BuddyStats
Get allocator statistics
Sourcepub fn get_memory_usage(&self) -> MemoryUsage
pub fn get_memory_usage(&self) -> MemoryUsage
Get current memory usage
Sourcepub fn get_free_block_stats(&self) -> Vec<FreeBlockStats>
pub fn get_free_block_stats(&self) -> Vec<FreeBlockStats>
Get detailed statistics about free blocks
Sourcepub fn validate_consistency(&self) -> Result<(), BuddyError>
pub fn validate_consistency(&self) -> Result<(), BuddyError>
Check allocator consistency
Sourcepub fn access_block(&mut self, ptr: *mut u8) -> Result<(), BuddyError>
pub fn access_block(&mut self, ptr: *mut u8) -> Result<(), BuddyError>
Access a previously allocated block (for statistics)
Sourcepub fn get_allocation_info(&self, ptr: *mut u8) -> Option<AllocationInfo>
pub fn get_allocation_info(&self, ptr: *mut u8) -> Option<AllocationInfo>
Get allocation info for a pointer
Trait Implementations§
impl Send for BuddyAllocator
impl Sync for BuddyAllocator
Auto Trait Implementations§
impl Freeze for BuddyAllocator
impl RefUnwindSafe for BuddyAllocator
impl Unpin for BuddyAllocator
impl UnsafeUnpin for BuddyAllocator
impl UnwindSafe for BuddyAllocator
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
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