pub struct BuddyAlloc {
base_addr: usize,
end_addr: usize,
unavailable: usize,
entries: *mut Entry,
entries_size: usize,
leaf2base: usize,
}Fields§
§base_addr: usizememory start addr
end_addr: usizememory end addr
unavailable memories at end_addr
entries: *mut Entry§entries_size: usize§leaf2base: usizemin size of a block, represent in 1 << leaf2base
Implementations§
Source§impl BuddyAlloc
impl BuddyAlloc
Sourcepub unsafe fn new(param: BuddyAllocParam) -> Self
pub unsafe fn new(param: BuddyAllocParam) -> Self
§Safety
The base_addr..(base_addr + len) must be allocated before using,
and must guarantee no others write to the memory range, to avoid undefined behaviors.
The new function panic if memory space not enough for initialize BuddyAlloc.
fn init_free_list(&mut self)
pub fn malloc(&mut self, nbytes: usize) -> *mut u8
pub fn free(&mut self, p: *mut u8)
fn entry(&self, i: usize) -> &Entry
Sourcefn find_k_for_p(&self, p: *const u8) -> usize
fn find_k_for_p(&self, p: *const u8) -> usize
find k for p
Sourcefn block_addr(&self, k: usize, i: usize) -> usize
fn block_addr(&self, k: usize, i: usize) -> usize
block addr of index under k
Auto Trait Implementations§
impl Freeze for BuddyAlloc
impl RefUnwindSafe for BuddyAlloc
impl !Send for BuddyAlloc
impl !Sync for BuddyAlloc
impl Unpin for BuddyAlloc
impl UnwindSafe for BuddyAlloc
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<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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