pub trait Heap {
// Required methods
fn new() -> Self
where Self: Sized;
fn allocate(&self, layout: Layout) -> Result<NonNull<u8>, AllocError>;
unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout);
// Provided method
unsafe fn reallocate(
&self,
ptr: NonNull<u8>,
old_layout: Layout,
new_size: usize,
) -> Result<NonNull<u8>, AllocError> { ... }
}
🔬This is a nightly-only experimental API. (
kernel_heap
#4)Expand description
A heap manager
Required Methods§
Sourcefn new() -> Selfwhere
Self: Sized,
🔬This is a nightly-only experimental API. (kernel_heap
#4)
fn new() -> Selfwhere
Self: Sized,
kernel_heap
#4)Creates a new instance of the heap manager
Sourcefn allocate(&self, layout: Layout) -> Result<NonNull<u8>, AllocError>
🔬This is a nightly-only experimental API. (kernel_heap
#4)
fn allocate(&self, layout: Layout) -> Result<NonNull<u8>, AllocError>
kernel_heap
#4)Allocates a new area of memory for layout
§Errors
Returns AllocError
if the memory could not be allocated
Sourceunsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout)
🔬This is a nightly-only experimental API. (kernel_heap
#4)
unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout)
kernel_heap
#4)Deallocates the memory pointed to by ptr
§Safety
The ptr
must have been previously allocated by the same allocator with the same layout as layout
Provided Methods§
Sourceunsafe fn reallocate(
&self,
ptr: NonNull<u8>,
old_layout: Layout,
new_size: usize,
) -> Result<NonNull<u8>, AllocError>
🔬This is a nightly-only experimental API. (kernel_heap
#4)
unsafe fn reallocate( &self, ptr: NonNull<u8>, old_layout: Layout, new_size: usize, ) -> Result<NonNull<u8>, AllocError>
kernel_heap
#4)Adjusts the size of the allocation pointed to by ptr
§Safety
The ptr
must have been previously allocated by the same allocator with the same layout as old_layout
§Errors
If the size could not be adjusted, returns AllocError
and the old pointer is still valid to the original allocation.