[−][src]Trait alloc_compose::ReallocInPlace
Required methods
unsafe fn grow_in_place(
&mut self,
ptr: NonNull<u8>,
layout: Layout,
new_size: usize
) -> Result<usize, AllocErr>
&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 (Thenew_size
argument need not fit it.),new_size
must be greater than or equal tolayout.size()
, andnew_size
, when rounded up to the nearest multiple oflayout.align()
, must not overflow (i.e., the rounded value must be less than or equal tousize::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>
&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 theMemoryBlock
prior to thegrow_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 theMemoryBlock
returned by thegrow
call.
Safety
ptr
must denote a block of memory currently allocated via this allocator,layout
must fit that block of memory (Thenew_size
argument need not fit it.),new_size
must be greater than or equal tolayout.size()
, andnew_size
, when rounded up to the nearest multiple oflayout.align()
, must not overflow (i.e., the rounded value must be less than or equal tousize::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>
&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 (Thenew_size
argument need not fit it.), andnew_size
must be smaller than or equal tolayout.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.
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]
&mut self,
_ptr: NonNull<u8>,
_layout: Layout,
_new_size: usize
) -> Result<usize, AllocErr>
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]
&mut self,
_ptr: NonNull<u8>,
_layout: Layout,
_new_size: usize
) -> Result<usize, AllocErr>
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]
&mut self,
_ptr: NonNull<u8>,
_layout: Layout,
_new_size: usize
) -> Result<usize, AllocErr>
Must not be called, as allocation always fails.
impl<'_> ReallocInPlace for Region<'_>
[src]
unsafe fn grow_in_place(
&mut self,
ptr: NonNull<u8>,
layout: Layout,
new_size: usize
) -> Result<usize, AllocErr>
[src]
&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>
[src]
&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>
[src]
&mut self,
ptr: NonNull<u8>,
layout: Layout,
new_size: usize
) -> Result<usize, AllocErr>
impl<A: ReallocInPlace, C: CallbackRef> ReallocInPlace for Proxy<A, C>
[src]
unsafe fn grow_in_place(
&mut self,
ptr: NonNull<u8>,
layout: Layout,
new_size: usize
) -> Result<usize, AllocErr>
[src]
&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>
[src]
&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>
[src]
&mut self,
ptr: NonNull<u8>,
layout: Layout,
new_size: usize
) -> Result<usize, AllocErr>
impl<A: ReallocInPlace, const SIZE: usize> ReallocInPlace for Chunk<A, SIZE> where
Self: SizeIsPowerOfTwo,
[src]
Self: SizeIsPowerOfTwo,
unsafe fn grow_in_place(
&mut self,
ptr: NonNull<u8>,
layout: Layout,
new_size: usize
) -> Result<usize, AllocErr>
[src]
&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>
[src]
&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>
[src]
&mut self,
ptr: NonNull<u8>,
layout: Layout,
new_size: usize
) -> Result<usize, AllocErr>
impl<Alloc, Prefix, Suffix> ReallocInPlace for Affix<Alloc, Prefix, Suffix> where
Alloc: ReallocInPlace,
[src]
Alloc: ReallocInPlace,
unsafe fn grow_in_place(
&mut self,
ptr: NonNull<u8>,
layout: Layout,
new_size: usize
) -> Result<usize, AllocErr>
[src]
&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>
[src]
&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>
[src]
&mut self,
ptr: NonNull<u8>,
layout: Layout,
new_size: usize
) -> Result<usize, AllocErr>