Under heavy development. This site describes the intended 1.0 language. Current features and performance vary. Development status
Sn50SnThe SnAPI programming language
0.2.0 Preview 1 · Frozen documentation

Allocator

Defines the structural raw-storage protocol used by owning containers.

Sn is under heavy development. Reference extracted from this release’s bundled standard library. Public API examples are not an exhaustive compatibility test. Read the matching release guide for tested workflows and limitations. Read the status →

Module std.memory

import std.memory;

Public declaration contracts and authored examples. A page can document several related symbols. Implementation bodies are excluded.

Allocator

pub concept Allocator<Self>

Defines the structural raw-storage protocol used by owning containers.

An allocator starts and ends allocation storage only; it never begins or ends a T object lifetime. Every operation is unsafe because callers own the exact identity, layout, lifetime, alias, and compatibility proofs.

Example

module example.allocator;
from std.memory import DefaultAllocator, Layout;
fn Main() -> i32 {
    var Heap = default(DefaultAllocator);
    let StorageLayout = Layout.Of<u64>();
    unsafe {
        switch Heap.Allocate(StorageLayout) {
            case .Ok { Value = Storage } => {
                Heap.Free(Storage, StorageLayout);
                return 0;
            }
            case .Err { Error = _ } => return 1;
        }
    }
}

Allocator.Allocate

requires unsafe fn Allocate(StorageLayout: Layout)
        -> Result<mut byte*, AllocationError>;

Acquires one distinct nonnull allocation identity. StorageLayout: Exact valid requested layout. Return: Writable raw bytes or a recoverable allocation error.

Allocator.Free

requires unsafe fn Free(
        Storage: mut byte*,
        StorageLayout: Layout
    ) -> void;

Releases one compatible allocation without destroying objects. Storage: Exact base pointer, or null only with default(Layout). StorageLayout: Exact layout used to acquire nonnull storage. Return: No value after the allocation lifetime ends.

Documentation snapshot: October 24, 2026 About versions ↗
Searching Development · language & standard library