docs

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 LayoutError
  • pub const fn message(self) -> str§

    Source

    What went wrong, for display.

Trait implementations 6
  • impl PartialEq for LayoutError
  • impl Eq for LayoutError
  • impl Clone for LayoutError
  • impl Display for LayoutError
  • impl Debug for LayoutError
  • impl Error for LayoutError

LayoutSource

pub struct Layout

Size and alignment of a raw block.

  • pub const fn new<T>() -> Layout§

    Source

    The layout of one T.

  • pub const fn array<T>(n: usize) throws (LayoutError) -> Layout§

    Source

    The layout of n Ts.

  • pub const fn from_size_align(size: usize, align: usize) throws (LayoutError) -> Layout§

    Source

    align must be a power of two.

  • pub const fn size(self) -> usize§

    Source

    The size in bytes.

  • pub const fn align(self) -> usize§

    Source

    The alignment in bytes, a power of two.

Trait implementations 6

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.

  • pub fn new(n: usize) throws (LayoutError) -> Allocation<T>§

    Source

    Room for n Ts (zeroed); LayoutError when the size overflows or the system has no memory.

  • pub const fn as_ptr(self) -> Ptr<T>§

    Source

    The first element.

  • pub const fn as_many(self) -> ManyPtr<T>§

    Source

    The first element, as a pointer to the run.

  • pub const fn len(self) -> usize§

    Source

    The number of Ts it has room for.

Trait implementations 2
  • impl<T> Debug for Allocation<T>
  • impl<T> Drop for Allocation<T>

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.