Skip to main content

Realloc

Trait Realloc 

Source
pub trait Realloc: Grow + Shrink {
    // Provided methods
    unsafe fn realloc(
        &self,
        ptr: NonNull<u8>,
        old_layout: Layout,
        new_layout: Layout,
    ) -> Result<NonNull<u8>, Self::Error> { ... }
    unsafe fn rezalloc(
        &self,
        ptr: NonNull<u8>,
        old_layout: Layout,
        new_layout: Layout,
    ) -> Result<NonNull<u8>, Self::Error> { ... }
}
Expand description

A memory allocation interface which can arbitrarily resize allocations.

Provided Methods§

Source

unsafe fn realloc( &self, ptr: NonNull<u8>, old_layout: Layout, new_layout: Layout, ) -> Result<NonNull<u8>, Self::Error>

Reallocates a block, growing or shrinking as needed.

On grow, preserves existing contents up to old_layout.size(), and on shrink, truncates to new_layout.size().

On failure, the original memory will not be deallocated.

Returns a dangling pointer if layout.size() == 0.

§Safety

The caller must ensure:

  • ptr points to a block previously allocated with this allocator.
  • old_layout describes exactly the same block.
§Errors

Errors are implementation-defined, refer to [Self::Error] and Error.

The standard implementations may return:

Source

unsafe fn rezalloc( &self, ptr: NonNull<u8>, old_layout: Layout, new_layout: Layout, ) -> Result<NonNull<u8>, Self::Error>

Reallocates a block, growing or shrinking as needed, with extra bytes being zeroed.

On grow, preserves existing contents up to old_layout.size(), and on shrink, truncates to new_layout.size().

On failure, the original memory will not be deallocated.

Returns a dangling pointer if layout.size() == 0.

§Safety

The caller must ensure:

  • ptr points to a block previously allocated with this allocator.
  • old_layout describes exactly the same block.
§Errors

Errors are implementation-defined, refer to [Self::Error] and Error.

The standard implementations may return:

Implementations on Foreign Types§

Source§

impl Realloc for Global

Available on non-crate feature no_alloc only.
Source§

impl Realloc for System

Available on crate feature std and non-crate feature no_alloc only.
Source§

impl<A: Realloc + ?Sized> Realloc for &A

Source§

unsafe fn realloc( &self, ptr: NonNull<u8>, old_layout: Layout, new_layout: Layout, ) -> Result<NonNull<u8>, Self::Error>

Source§

unsafe fn rezalloc( &self, ptr: NonNull<u8>, old_layout: Layout, new_layout: Layout, ) -> Result<NonNull<u8>, Self::Error>

Source§

impl<A: Realloc + ?Sized> Realloc for &mut A

Source§

unsafe fn realloc( &self, ptr: NonNull<u8>, old_layout: Layout, new_layout: Layout, ) -> Result<NonNull<u8>, Self::Error>

Source§

unsafe fn rezalloc( &self, ptr: NonNull<u8>, old_layout: Layout, new_layout: Layout, ) -> Result<NonNull<u8>, Self::Error>

Source§

impl<A: Realloc + ?Sized> Realloc for Box<A>

Source§

unsafe fn realloc( &self, ptr: NonNull<u8>, old_layout: Layout, new_layout: Layout, ) -> Result<NonNull<u8>, Self::Error>

Source§

unsafe fn rezalloc( &self, ptr: NonNull<u8>, old_layout: Layout, new_layout: Layout, ) -> Result<NonNull<u8>, Self::Error>

Source§

impl<A: Realloc + ?Sized> Realloc for Rc<A>

Source§

unsafe fn realloc( &self, ptr: NonNull<u8>, old_layout: Layout, new_layout: Layout, ) -> Result<NonNull<u8>, Self::Error>

Source§

unsafe fn rezalloc( &self, ptr: NonNull<u8>, old_layout: Layout, new_layout: Layout, ) -> Result<NonNull<u8>, Self::Error>

Source§

impl<A: Realloc + ?Sized> Realloc for Arc<A>

Source§

unsafe fn realloc( &self, ptr: NonNull<u8>, old_layout: Layout, new_layout: Layout, ) -> Result<NonNull<u8>, Self::Error>

Source§

unsafe fn rezalloc( &self, ptr: NonNull<u8>, old_layout: Layout, new_layout: Layout, ) -> Result<NonNull<u8>, Self::Error>

Source§

impl<A: ReallocMut + ?Sized> Realloc for RefCell<A>

Source§

unsafe fn realloc( &self, ptr: NonNull<u8>, old_layout: Layout, new_layout: Layout, ) -> Result<NonNull<u8>, Self::Error>

Source§

unsafe fn rezalloc( &self, ptr: NonNull<u8>, old_layout: Layout, new_layout: Layout, ) -> Result<NonNull<u8>, Self::Error>

Source§

impl<A: ReallocMut + ?Sized> Realloc for Mutex<A>

Source§

unsafe fn realloc( &self, ptr: NonNull<u8>, old_layout: Layout, new_layout: Layout, ) -> Result<NonNull<u8>, Self::Error>

Source§

unsafe fn rezalloc( &self, ptr: NonNull<u8>, old_layout: Layout, new_layout: Layout, ) -> Result<NonNull<u8>, Self::Error>

Source§

impl<A: ReallocMut + ?Sized> Realloc for RwLock<A>

Source§

unsafe fn realloc( &self, ptr: NonNull<u8>, old_layout: Layout, new_layout: Layout, ) -> Result<NonNull<u8>, Self::Error>

Source§

unsafe fn rezalloc( &self, ptr: NonNull<u8>, old_layout: Layout, new_layout: Layout, ) -> Result<NonNull<u8>, Self::Error>

Implementors§

Source§

impl Realloc for CAlloc

Source§

impl Realloc for DefaultAlloc

Available on non-crate feature no_alloc only.