Skip to main content

Deallocator

Trait Deallocator 

Source
pub trait Deallocator {
    // Required method
    unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: NonZeroLayout);

    // Provided methods
    unsafe fn try_shrink(
        &self,
        ptr: NonNull<u8>,
        old_layout: NonZeroLayout,
        new_layout: NonZeroLayout,
    ) -> Result<(), AllocError> { ... }
    fn by_ref(&self) -> &Self
       where Self: Sized { ... }
}
Expand description

A Deallocator can be used to deallocate or shrink an allocation described by a NonZeroLayout.

Required Methods§

Source

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

Deallocates the memory referenced by ptr.

§Safety
  • The pointer must be valid and the same as given by a previous call to allocate.
  • The layout must be identical to that used when allocating the pointer.

Provided Methods§

Source

unsafe fn try_shrink( &self, ptr: NonNull<u8>, old_layout: NonZeroLayout, new_layout: NonZeroLayout, ) -> Result<(), AllocError>

Attempt to shrink a block of memory in-place.

§Safety
  • The pointer must be valid and the same as returned by a previous call to allocate.
  • The old layout must be identical to that used when allocating the pointer
  • The new layout must have a size and alignment such that new_size <= old_size and new_align <= old_align.
Source

fn by_ref(&self) -> &Self
where Self: Sized,

Creates a “by reference” adapter for this instance of Dellocator. The returned adapter also implements Deallocator and will simply borrow this.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<'a, A> Deallocator for &'a A
where A: Deallocator + ?Sized,

Source§

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

Source§

unsafe fn try_shrink( &self, ptr: NonNull<u8>, old_layout: NonZeroLayout, new_layout: NonZeroLayout, ) -> Result<(), AllocError>

Implementors§