Trait Allocator

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

Source

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.

Source

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.

Source

fn get_entries(&self) -> *mut u8

Gets the current entries pointer.

Source

fn set_entries(&mut self, entries: *mut u8)

Sets the entries pointer.

Provided Methods§

Source

fn min_size() -> u32

Returns the minimum size that can be allocated by this allocator.

Must be > 0.

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.

Implementors§