Trait rlsf::CAlloc

source ·
pub unsafe trait CAlloc {
    // Required methods
    fn allocate(&self, layout: Layout) -> Option<NonNull<u8>>;
    unsafe fn deallocate(&self, ptr: NonNull<u8>);
    unsafe fn reallocate(
        &self,
        ptr: NonNull<u8>,
        new_layout: Layout
    ) -> Option<NonNull<u8>>;
    unsafe fn allocation_usable_size(&self, ptr: NonNull<u8>) -> usize;
}
Available on WebAssembly and non-target feature atomics, or Unix only.
Expand description

Provides allocation functions modelled after the standard C and POSIX allocation functions (e.g., malloc, memalign).

Note that this trait might require a less efficient implementation than core::alloc::GlobalAlloc. This applies to GlobalTlsf.

Required Methods§

source

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

Allocate a memory block.

Returns the starting address of the allocated memory block on success; None otherwise.

source

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

Deallocate a previously allocated memory block.

Safety
  • ptr must denote a memory block previously allocated by calling Self::allocate on self.
source

unsafe fn reallocate( &self, ptr: NonNull<u8>, new_layout: Layout ) -> Option<NonNull<u8>>

Shrink or grow a previously allocated memory block.

Returns the new starting address of the memory block on success; None otherwise.

Safety
  • ptr must denote a memory block previously allocated by calling Self::allocate on self.
source

unsafe fn allocation_usable_size(&self, ptr: NonNull<u8>) -> usize

Get the actual usable size of a previously allocated memory block.

Safety
  • ptr must denote a memory block previously allocated by calling Self::allocate on self.

Implementors§

source§

impl<Options: GlobalTlsfOptions> CAlloc for GlobalTlsf<Options>