rokdocs
v0.1

rok::bare::alloc

rok::bare::alloc - raw allocation outside the GC (stdlib spec 1.4). Over the runtime's rok_alloc_raw / rok_realloc_raw / rok_free (system malloc); failure is a null CPtr, never an abort.

Allocation<T> frees its block when its using block ends.

Structs

LayoutError

pub struct LayoutError

Why a Layout cannot be made.

  • pub reason: str

Layout

pub struct Layout

Size and alignment of a raw block.

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

    The layout of one T.

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

    The layout of n Ts.

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

    align must be a power of two.

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

Allocation

pub struct Allocation<T>

n Ts outside the GC, freed when the using block holding it ends (spec 1.4.2). Copies share the block; use it only inside that block.

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

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

  • pub const fn as_ptr(self) -> Ptr<T>
  • pub const fn as_many(self) -> ManyPtr<T>
  • pub const fn len(self) -> usize
Trait implementations 1
  • impl<T> Drop for Allocation<T>

Functions

alloc

pub unsafe fn alloc(layout: Layout) -> CPtr<u8>

alloc_zeroed

pub unsafe fn alloc_zeroed(layout: Layout) -> CPtr<u8>

dealloc

pub unsafe fn dealloc(ptr: Ptr<u8>, layout: Layout)

realloc

pub unsafe fn realloc(ptr: Ptr<u8>, old_layout: Layout, new_size: usize) -> CPtr<u8>

On failure (null) ptr is still valid.

alloc_one

pub unsafe fn alloc_one<T>() -> CPtr<T>

alloc_array

pub unsafe fn alloc_array<T>(n: usize) -> CPtr<T>

dealloc_one

pub unsafe fn dealloc_one<T>(ptr: Ptr<T>)

dealloc_array

pub unsafe fn dealloc_array<T>(ptr: Ptr<T>, n: usize)