pub unsafe trait Allocator<'a> {
// Required methods
fn allocate(
&mut self,
layout: Layout,
) -> Result<NonNull<u8>, AllocationError>;
fn deallocate(
&mut self,
ptr: NonNull<u8>,
layout: Layout,
) -> Result<(), AllocationError>;
unsafe fn refill_large(
&mut self,
layout: Layout,
new_page: &'a mut LargeObjectPage<'a>,
) -> Result<(), AllocationError>;
unsafe fn refill(
&mut self,
layout: Layout,
new_page: &'a mut ObjectPage<'a>,
) -> Result<(), AllocationError>;
}Expand description
Allocator trait to be implemented by users of slabmalloc to provide memory to slabmalloc.
§Safety
Needs to adhere to safety requirements of a rust allocator (see GlobalAlloc et. al.).
Required Methods§
fn allocate(&mut self, layout: Layout) -> Result<NonNull<u8>, AllocationError>
fn deallocate( &mut self, ptr: NonNull<u8>, layout: Layout, ) -> Result<(), AllocationError>
Sourceunsafe fn refill_large(
&mut self,
layout: Layout,
new_page: &'a mut LargeObjectPage<'a>,
) -> Result<(), AllocationError>
unsafe fn refill_large( &mut self, layout: Layout, new_page: &'a mut LargeObjectPage<'a>, ) -> Result<(), AllocationError>
Refill the allocator with a LargeObjectPage.
§Safety
TBD (this API needs to change anyways, likely new page should be a raw pointer)
Sourceunsafe fn refill(
&mut self,
layout: Layout,
new_page: &'a mut ObjectPage<'a>,
) -> Result<(), AllocationError>
unsafe fn refill( &mut self, layout: Layout, new_page: &'a mut ObjectPage<'a>, ) -> Result<(), AllocationError>
Refill the allocator with a ObjectPage.
§Safety
TBD (this API needs to change anyways, likely new page should be a raw pointer)