[][src]Trait alloc_compose::ReallocateInPlace

pub unsafe trait ReallocateInPlace {
    pub unsafe fn grow_in_place(
        &self,
        ptr: NonNull<u8>,
        old_layout: Layout,
        new_layout: Layout
    ) -> Result<usize, AllocError>;
pub unsafe fn grow_in_place_zeroed(
        &self,
        ptr: NonNull<u8>,
        old_layout: Layout,
        new_layout: Layout
    ) -> Result<usize, AllocError>;
pub unsafe fn shrink_in_place(
        &self,
        ptr: NonNull<u8>,
        old_layout: Layout,
        new_layout: Layout
    ) -> Result<usize, AllocError>; }

Extends AllocRef to support growing and shrinking in place.

Required methods

pub unsafe fn grow_in_place(
    &self,
    ptr: NonNull<u8>,
    old_layout: Layout,
    new_layout: Layout
) -> Result<usize, AllocError>
[src]

Attempts to extend the memory block.

Returns the new actual size of the allocated memory. The pointer is suitable for holding data described by a new layout with layout’s alignment and a size given by new_size. To accomplish this, the allocator may extend the allocation referenced by ptr to fit the new layout.

If this method returns Err, the allocator was not able to grow the memory without changing the pointer. The ownership of the memory block has not been transferred to this allocator, and the contents of the memory block are unaltered.

Safety

  • ptr must denote a block of memory currently allocated via this allocator.
  • old_layout must fit that block of memory (The new_layout argument need not fit it.).
  • new_layout.size() must be greater than or equal to old_layout.size().

Errors

Returns Err if the new layout does not meet the allocators size and alignment constraints of the allocator, or if growing otherwise fails.

Implementations are encouraged to return Err on memory exhaustion rather than panicking or aborting, but this is not a strict requirement. (Specifically: it is legal to implement this trait atop an underlying native allocation library that aborts on memory exhaustion.)

Clients wishing to abort computation in response to an allocation error are encouraged to call the handle_alloc_error function, rather than directly invoking panic! or similar.

pub unsafe fn grow_in_place_zeroed(
    &self,
    ptr: NonNull<u8>,
    old_layout: Layout,
    new_layout: Layout
) -> Result<usize, AllocError>
[src]

Behaves like grow_in_place, but also ensures that the new contents are set to zero before being returned.

The memory block will contain the following contents after a successful call to grow_zeroed:

  • Bytes 0..old_layout.size() are preserved from the original allocation.
  • Bytes old_layout.size()..old_size will either be preserved or zeroed, depending on the allocator implementation. old_size refers to the size of the memory block prior to the grow_zeroed call, which may be larger than the size that was originally requested when it was allocated.
  • Bytes old_size..new_size are zeroed. new_size refers to the size of the memory block returned by the grow_zeroed call.

Safety

  • ptr must denote a block of memory currently allocated via this allocator.
  • old_layout must fit that block of memory (The new_layout argument need not fit it.).
  • new_layout.size() must be greater than or equal to old_layout.size().

Errors

Returns Err if the new layout does not meet the allocators size and alignment constraints of the allocator, or if growing otherwise fails.

Implementations are encouraged to return Err on memory exhaustion rather than panicking or aborting, but this is not a strict requirement. (Specifically: it is legal to implement this trait atop an underlying native allocation library that aborts on memory exhaustion.)

Clients wishing to abort computation in response to an allocation error are encouraged to call the handle_alloc_error function, rather than directly invoking panic! or similar.

pub unsafe fn shrink_in_place(
    &self,
    ptr: NonNull<u8>,
    old_layout: Layout,
    new_layout: Layout
) -> Result<usize, AllocError>
[src]

Attempts to shrink the memory block.

Returns the new actual size of the allocated memory. The pointer is suitable for holding data described by a new layout with layout’s alignment and a size given by new_size. To accomplish this, the allocator may extend the allocation referenced by ptr to fit the new layout.

If this method returns Err, the allocator was not able to shrink the memory without changing the pointer. The ownership of the memory block has not been transferred to this allocator, and the contents of the memory block are unaltered.

Safety

  • ptr must denote a block of memory currently allocated via this allocator.
  • old_layout must fit that block of memory (The new_layout argument need not fit it.).
  • new_layout.size() must be smaller than or equal to old_layout.size().

Errors

Returns Err if the new layout does not meet the allocator's size and alignment constraints of the allocator, or if shrinking otherwise fails.

Implementations are encouraged to return Err on memory exhaustion rather than panicking or aborting, but this is not a strict requirement. (Specifically: it is legal to implement this trait atop an underlying native allocation library that aborts on memory exhaustion.)

Clients wishing to abort computation in response to an allocation error are encouraged to call the handle_alloc_error function, rather than directly invoking panic! or similar.

Loading content...

Implementations on Foreign Types

impl<A: ?Sized> ReallocateInPlace for Box<A> where
    A: ReallocateInPlace
[src]

This is supported on crate feature alloc only.

impl<A: ?Sized> ReallocateInPlace for Rc<A> where
    A: ReallocateInPlace
[src]

This is supported on crate feature alloc only.

impl<A: ?Sized> ReallocateInPlace for Arc<A> where
    A: ReallocateInPlace
[src]

This is supported on crate feature alloc only.
Loading content...

Implementors

impl ReallocateInPlace for Null[src]

pub unsafe fn grow_in_place(
    &self,
    _ptr: NonNull<u8>,
    _old_layout: Layout,
    _new_layout: Layout
) -> Result<usize, AllocError>
[src]

Must not be called, as allocation always fails.

pub unsafe fn grow_in_place_zeroed(
    &self,
    _ptr: NonNull<u8>,
    _old_layout: Layout,
    _new_layout: Layout
) -> Result<usize, AllocError>
[src]

Must not be called, as allocation always fails.

pub unsafe fn shrink_in_place(
    &self,
    _ptr: NonNull<u8>,
    _old_layout: Layout,
    _new_layout: Layout
) -> Result<usize, AllocError>
[src]

Must not be called, as allocation always fails.

impl<A, const SIZE: usize> ReallocateInPlace for Chunk<A, SIZE> where
    Self: SizeIsPowerOfTwo, 
[src]

impl<A: ReallocateInPlace, C: CallbackRef> ReallocateInPlace for Proxy<A, C>[src]

impl<A: ReallocateInPlace, const SIZE: usize> ReallocateInPlace for Chunk<A, SIZE> where
    Self: SizeIsPowerOfTwo, 
[src]

impl<A: ?Sized, '_> ReallocateInPlace for &'_ A where
    A: ReallocateInPlace
[src]

Loading content...