Trait stabby::alloc::IAlloc

source ·
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§

source

fn alloc(&mut self, layout: Layout) -> *mut ()

Allocates at least as much memory as requested by layout, ensuring the requested alignment is respected.

If the requested size is 0, or allocation failed, then a null pointer is returned.

source

unsafe fn free(&mut self, ptr: *mut ())

Frees the allocation

§Safety

ptr MUST have been allocated through a succesful call to Self::alloc or Self::realloc with the same instance of Self

Provided Methods§

source

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

Implementations on Foreign Types§

source§

impl IAlloc for Infallible

source§

fn alloc(&mut self, _layout: Layout) -> *mut ()

source§

unsafe fn free(&mut self, _ptr: *mut ())

Implementors§