[−][src]Trait alloc_compose::ReallocateInPlace
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]
&self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout
) -> Result<usize, AllocError>
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
ptrmust denote a block of memory currently allocated via this allocator.old_layoutmust fit that block of memory (Thenew_layoutargument need not fit it.).new_layout.size()must be greater than or equal toold_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]
&self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout
) -> Result<usize, AllocError>
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_sizewill either be preserved or zeroed, depending on the allocator implementation.old_sizerefers to the size of the memory block prior to thegrow_zeroedcall, which may be larger than the size that was originally requested when it was allocated. - Bytes
old_size..new_sizeare zeroed.new_sizerefers to the size of the memory block returned by thegrow_zeroedcall.
Safety
ptrmust denote a block of memory currently allocated via this allocator.old_layoutmust fit that block of memory (Thenew_layoutargument need not fit it.).new_layout.size()must be greater than or equal toold_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]
&self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout
) -> Result<usize, AllocError>
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
ptrmust denote a block of memory currently allocated via this allocator.old_layoutmust fit that block of memory (Thenew_layoutargument need not fit it.).new_layout.size()must be smaller than or equal toold_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.
Implementations on Foreign Types
impl<A: ?Sized> ReallocateInPlace for Box<A> where
A: ReallocateInPlace, [src]
A: ReallocateInPlace,
alloc only.pub unsafe fn grow_in_place(
&self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout
) -> Result<usize, AllocError>[src]
&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>[src]
&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>[src]
&self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout
) -> Result<usize, AllocError>
impl<A: ?Sized> ReallocateInPlace for Rc<A> where
A: ReallocateInPlace, [src]
A: ReallocateInPlace,
alloc only.pub unsafe fn grow_in_place(
&self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout
) -> Result<usize, AllocError>[src]
&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>[src]
&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>[src]
&self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout
) -> Result<usize, AllocError>
impl<A: ?Sized> ReallocateInPlace for Arc<A> where
A: ReallocateInPlace, [src]
A: ReallocateInPlace,
alloc only.pub unsafe fn grow_in_place(
&self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout
) -> Result<usize, AllocError>[src]
&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>[src]
&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>[src]
&self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout
) -> Result<usize, AllocError>
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]
&self,
_ptr: NonNull<u8>,
_old_layout: Layout,
_new_layout: Layout
) -> Result<usize, AllocError>
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]
&self,
_ptr: NonNull<u8>,
_old_layout: Layout,
_new_layout: Layout
) -> Result<usize, AllocError>
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]
&self,
_ptr: NonNull<u8>,
_old_layout: Layout,
_new_layout: Layout
) -> Result<usize, AllocError>
Must not be called, as allocation always fails.
impl<A, const SIZE: usize> ReallocateInPlace for Chunk<A, SIZE> where
Self: SizeIsPowerOfTwo, [src]
Self: SizeIsPowerOfTwo,
pub unsafe default fn grow_in_place(
&self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout
) -> Result<usize, AllocError>[src]
&self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout
) -> Result<usize, AllocError>
pub unsafe default fn grow_in_place_zeroed(
&self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout
) -> Result<usize, AllocError>[src]
&self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout
) -> Result<usize, AllocError>
pub unsafe default fn shrink_in_place(
&self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout
) -> Result<usize, AllocError>[src]
&self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout
) -> Result<usize, AllocError>
impl<A: ReallocateInPlace, C: CallbackRef> ReallocateInPlace for Proxy<A, C>[src]
pub unsafe fn grow_in_place(
&self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout
) -> Result<usize, AllocError>[src]
&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>[src]
&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>[src]
&self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout
) -> Result<usize, AllocError>
impl<A: ReallocateInPlace, const SIZE: usize> ReallocateInPlace for Chunk<A, SIZE> where
Self: SizeIsPowerOfTwo, [src]
Self: SizeIsPowerOfTwo,
pub unsafe fn grow_in_place(
&self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout
) -> Result<usize, AllocError>[src]
&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>[src]
&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>[src]
&self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout
) -> Result<usize, AllocError>
impl<A: ?Sized, '_> ReallocateInPlace for &'_ A where
A: ReallocateInPlace, [src]
A: ReallocateInPlace,
pub unsafe fn grow_in_place(
&self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout
) -> Result<usize, AllocError>[src]
&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>[src]
&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>[src]
&self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout
) -> Result<usize, AllocError>