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§
Sourceunsafe fn deallocate(&self, ptr: NonNull<u8>, layout: NonZeroLayout)
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§
Sourceunsafe fn try_shrink(
&self,
ptr: NonNull<u8>,
old_layout: NonZeroLayout,
new_layout: NonZeroLayout,
) -> Result<(), AllocError>
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.