pub struct Heap {
pub(crate) slabs: [Slab; 7],
pub(crate) fallback: Heap,
pub(crate) user: usize,
pub(crate) allocated: usize,
pub(crate) total: usize,
}Expand description
堆内存分配器
Fields§
§slabs: [Slab; 7]Slab 分配器数组
fallback: HeapFallback Linked List Allocator
user: usize用户请求的字节数
allocated: usize实际分配的字节数
total: usize堆中的总字节数
Implementations§
Source§impl Heap
impl Heap
Sourcepub unsafe fn add_to_heap(&mut self, start: usize, end: usize)
pub unsafe fn add_to_heap(&mut self, start: usize, end: usize)
添加一段内存[start, end)到堆中
由于 Linked List Allocator 需要一个连续的内存块, 所以不会在此被扩展
Sourcepub(crate) unsafe fn init_fallback(&mut self, start: usize, size: usize)
pub(crate) unsafe fn init_fallback(&mut self, start: usize, size: usize)
初始化 Fallback Allocator (Linked List Allocator)
只能被调用一次
Sourcepub unsafe fn extend_fallback(&mut self, size: usize)
pub unsafe fn extend_fallback(&mut self, size: usize)
扩展 Fallback Allocator (Linked List Allocator) 的内存
仅扩展 Linked List Allocator 之后的内存,需要确保 Linked List Allocator 已经初始化 并且内存空间 [start + original_size, start + original_size + size) 未被使用
Sourcepub(crate) fn select_allocator(&self, layout: &Layout) -> AllocType
pub(crate) fn select_allocator(&self, layout: &Layout) -> AllocType
Sourcepub fn stats_alloc_user(&self) -> usize
pub fn stats_alloc_user(&self) -> usize
返回用户请求的字节数
Sourcepub fn stats_alloc_actual(&self) -> usize
pub fn stats_alloc_actual(&self) -> usize
返回实际分配的字节数
Sourcepub fn stats_total_bytes(&self) -> usize
pub fn stats_total_bytes(&self) -> usize
返回堆中的总字节数
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Heap
impl RefUnwindSafe for Heap
impl Send for Heap
impl !Sync for Heap
impl Unpin for Heap
impl !UnwindSafe for Heap
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