[][src]Trait alloc_compose::ReallocInPlace

pub unsafe trait ReallocInPlace {
    unsafe fn grow_in_place(
        &mut self,
        ptr: NonNull<u8>,
        layout: Layout,
        new_size: usize
    ) -> Result<usize, AllocErr>;
unsafe fn grow_in_place_zeroed(
        &mut self,
        ptr: NonNull<u8>,
        layout: Layout,
        new_size: usize
    ) -> Result<usize, AllocErr>;
unsafe fn shrink_in_place(
        &mut self,
        ptr: NonNull<u8>,
        layout: Layout,
        new_size: usize
    ) -> Result<usize, AllocErr>; }

Required methods

unsafe fn grow_in_place(
    &mut self,
    ptr: NonNull<u8>,
    layout: Layout,
    new_size: usize
) -> Result<usize, AllocErr>

Attempts to extend the allocation referenced by ptr to fit new_layout.

Returns the a 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,
  • layout must fit that block of memory (The new_size argument need not fit it.),
  • new_size must be greater than or equal to layout.size(), and
  • new_size, when rounded up to the nearest multiple of layout.align(), must not overflow (i.e., the rounded value must be less than or equal to usize::MAX).

Errors

Returns Err if the new layout does not meet the allocator's 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.

unsafe fn grow_in_place_zeroed(
    &mut self,
    ptr: NonNull<u8>,
    layout: Layout,
    new_size: usize
) -> Result<usize, AllocErr>

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_in_place_zeroed:

  • Bytes 0..layout.size() are preserved from the original allocation.
  • Bytes layout.size()..old_size will either be preserved or zeroed, depending on the allocator implementation. old_size refers to the size of the MemoryBlock prior to the grow_in_place_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 MemoryBlock returned by the grow call.

Safety

  • ptr must denote a block of memory currently allocated via this allocator,
  • layout must fit that block of memory (The new_size argument need not fit it.),
  • new_size must be greater than or equal to layout.size(), and
  • new_size, when rounded up to the nearest multiple of layout.align(), must not overflow (i.e., the rounded value must be less than or equal to usize::MAX).

Errors

Returns Err if the new layout does not meet the allocator's 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.

unsafe fn shrink_in_place(
    &mut self,
    ptr: NonNull<u8>,
    layout: Layout,
    new_size: usize
) -> Result<usize, AllocErr>

Attempts to shrink the allocation referenced by ptr to fit new_layout.

Returns the a 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,
  • layout must fit that block of memory (The new_size argument need not fit it.), and
  • new_size must be smaller than or equal to layout.size()

Errors

Returns Err if the new layout does not meet the allocator's 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.

Loading content...

Implementors

impl ReallocInPlace for Null[src]

unsafe fn grow_in_place(
    &mut self,
    _ptr: NonNull<u8>,
    _layout: Layout,
    _new_size: usize
) -> Result<usize, AllocErr>
[src]

Must not be called, as allocation always fails.

unsafe fn grow_in_place_zeroed(
    &mut self,
    _ptr: NonNull<u8>,
    _layout: Layout,
    _new_size: usize
) -> Result<usize, AllocErr>
[src]

Must not be called, as allocation always fails.

unsafe fn shrink_in_place(
    &mut self,
    _ptr: NonNull<u8>,
    _layout: Layout,
    _new_size: usize
) -> Result<usize, AllocErr>
[src]

Must not be called, as allocation always fails.

impl<'_> ReallocInPlace for Region<'_>[src]

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

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

impl<Alloc, Prefix, Suffix> ReallocInPlace for Affix<Alloc, Prefix, Suffix> where
    Alloc: ReallocInPlace
[src]

Loading content...