pub trait IAlloc: Unpin {
// Required methods
fn alloc(&mut self, layout: Layout) -> *mut ();
unsafe fn free(&mut self, ptr: *mut ());
// Provided method
unsafe fn realloc(&mut self, ptr: *mut (), new_layout: Layout) -> *mut () { ... }
}
Expand description
An interface to an allocator.
Note that stabby
often stores allocators inside allocations they made, so allocators that cannot allocate
more than their size on stack will systematically fail to construct common stabby types.
Since the allocator may be moved, it must also be safe to do so, including after it has performed allocations.
Required Methods§
Provided Methods§
sourceunsafe fn realloc(&mut self, ptr: *mut (), new_layout: Layout) -> *mut ()
unsafe fn realloc(&mut self, ptr: *mut (), new_layout: Layout) -> *mut ()
Reallocates ptr
, ensuring that it has enough memory for the newly requested layout.
If the requested size is 0, or allocation failed, then a null pointer is returned, and ptr
is not freed.
§Safety
ptr
MUST have been allocated through a succesful call to Self::alloc
with the same instance of Self