pub unsafe trait CAlloc {
    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

Allocate a memory block.

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

Deallocate a previously allocated memory block.

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

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.

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