Skip to content
velt/mem exports

velt/mem

API reference

Facts about how values are stored, for code that manages its own memory layout, such as a container with slots for many values (Rust's std::mem), and Arena, a typed memory pool. Most programs never need this module; the collections are built on it. For a walkthrough, read the guide.

import { needsDrop, Blank, Arena } from "velt/mem";

Exports

Re-exported from velt/mem/needs_drop

function needsDrop<T>(value: T): bool

Whether values of value's type own memory that dropping one releases: strings, arrays, objects and class instances (and structs or unions holding any) do; numbers, bool and SIMD vectors do not. The same for every value of a type, and a constant where the type is known, so if (needsDrop(x)) costs nothing: a generic container can skip bookkeeping that only matters for values that hold memory (Rust's std::mem::needs_drop).

Re-exported from velt/mem/arena

class Arena<T>

A typed memory pool: values named by u32 index, released together by reset().

constructor(capacity: usize = 0)

capacity values fit before the pool first grows.

get length(): usize

Number of values allocated since the last reset().

alloc(value: T): u32

Stores value; returns its index.

get(index: u32): T

The value at index (a copy for Copy types, else a clone).

set(index: u32, value: T)

Replaces the value at index.

reset()

Drops every value but keeps the memory: the next allocations reuse it.

interface

Blank

#std/mem/blank.vlt:13

Re-exported from velt/mem/blank

interface Blank<T>

A value that owns no memory, for a container to keep in the slots it does not use (an array of plain T has no holes), so that a value it removes is released at once: "" for a string. Every type has it: one whose values own no memory (needsDrop is false) is its own blank, and one without a blank value gives the value itself (hasBlank() is false), which a container then replaces when that value goes. A type implements Blank to give one.

hasBlank(): bool

Whether blank() owns no memory (the same for every value of the type).

blank(): T

A value that owns no memory when hasBlank(); else this value.