pub trait Allocator {
// Required methods
unsafe fn allocate_zeroed(
&mut self,
layout: Layout,
) -> Result<NonNull<[u8]>, AllocError>;
unsafe fn deallocate(&mut self, ptr: NonNull<u8>, layout: Layout);
fn get_entries(&self) -> *mut u8;
fn set_entries(&mut self, entries: *mut u8);
// Provided method
fn min_size() -> u32 { ... }
}
Expand description
A trait representing a generic memory allocator. Provides methods for allocating and deallocating raw bytes.
Required Methods§
Sourceunsafe fn allocate_zeroed(
&mut self,
layout: Layout,
) -> Result<NonNull<[u8]>, AllocError>
unsafe fn allocate_zeroed( &mut self, layout: Layout, ) -> Result<NonNull<[u8]>, AllocError>
Allocates a block of memory of the specified size in bytes and initializes it to zero.
§Safety
See std::alloc::GlobalAlloc::alloc
.
§Errors
Returns AllocError
if the allocation fails.
Sourceunsafe fn deallocate(&mut self, ptr: NonNull<u8>, layout: Layout)
unsafe fn deallocate(&mut self, ptr: NonNull<u8>, layout: Layout)
Deallocates a previously allocated block of memory.
§Safety
This function is unsafe if called with an invalid or null pointer.
Sourcefn get_entries(&self) -> *mut u8
fn get_entries(&self) -> *mut u8
Gets the current entries pointer.
Sourcefn set_entries(&mut self, entries: *mut u8)
fn set_entries(&mut self, entries: *mut u8)
Sets the entries pointer.
Provided Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.