bare::alloc
On this page
raw allocation outside the GC.
Over the runtime's nabi_alloc_raw / nabi_realloc_raw / nabi_free
(system malloc); failure is a null CPtr, never an abort.
Allocation<T> frees its block where its owner leaves scope.
Structs
LayoutErrorSource
pub struct LayoutErrorWhat went wrong, for display.
LayoutSource
pub struct LayoutSize and alignment of a raw block.
The layout of one
T.
Sourcepub const fn array<T>(§n: usize) throws (LayoutError) -> Layout The layout of
nTs.
Sourcepub const fn from_size_align(§size: usize, align: usize) throws (LayoutError) -> Layout alignmust be a power of two.The size in bytes.
The alignment in bytes, a power of two.
AllocationSource
pub struct Allocation<T>n Ts outside the GC. It has one owner (let b = a
moves it), and the block is freed where that owner leaves scope.
Sourcepub fn new(§n: usize) throws (LayoutError) -> Allocation<T> Room for
nTs (zeroed);LayoutErrorwhen the size overflows or the system has no memory.The first element.
The first element, as a pointer to the run.
The number of
Ts it has room for.
Functions
allocSource
pub unsafe fn alloc(layout: Layout) -> CPtr<u8> A block for layout outside the GC, uninitialized; null when out of
memory or when the size is 0. Free it with dealloc and the same layout.
alloc_zeroedSource
pub unsafe fn alloc_zeroed(layout: Layout) -> CPtr<u8> Like alloc, with every byte zero; null when out of memory or when
the size is 0.
deallocSource
pub unsafe fn dealloc(ptr: Ptr<u8>, layout: Layout) Free a block from alloc / alloc_zeroed / realloc. UB unless
ptr came from one of them and is not freed yet.
reallocSource
pub unsafe fn realloc(ptr: Ptr<u8>, old_layout: Layout, new_size: usize) -> CPtr<u8> On failure (null) ptr is still valid.
alloc_oneSource
pub unsafe fn alloc_one<T>() -> CPtr<T> An uninitialized block for one T; null when out of memory or when
T has size 0. Free it with dealloc_one.
alloc_arraySource
pub unsafe fn alloc_array<T>(n: usize) -> CPtr<T> An uninitialized block for n Ts; null when out of memory, when
the size is 0 or when n * size_of::<T>() overflows. Free it with
dealloc_array.
dealloc_oneSource
pub unsafe fn dealloc_one<T>(ptr: Ptr<T>) Free a block from alloc_one. UB unless ptr came from it and is not
freed yet; the T is not dropped.
dealloc_arraySource
pub unsafe fn dealloc_array<T>(ptr: Ptr<T>, n: usize) Free a block of n Ts from alloc_array. UB unless ptr came
from it and is not freed yet; the elements are not dropped.