Trait Heap

Source
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§

Source

fn new() -> Self
where Self: Sized,

🔬This is a nightly-only experimental API. (kernel_heap #4)

Creates a new instance of the heap manager

Source

fn allocate(&self, layout: Layout) -> Result<NonNull<u8>, AllocError>

🔬This is a nightly-only experimental API. (kernel_heap #4)

Allocates a new area of memory for layout

§Errors

Returns AllocError if the memory could not be allocated

Source

unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout)

🔬This is a nightly-only experimental API. (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§

Source

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)

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.

Implementors§