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

TypedAllocation

Acquires raw storage for `Count` not-yet-live `T` objects.

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.

Allocate

pub unsafe fn Allocate<T, A>(
    Value: mut A&,
    Count: usize
) -> Result<mut T*, AllocationError>
    where A: Allocator

Acquires raw storage for Count not-yet-live T objects. T: Complete sized slot type whose lifetime is not started here. A: Concrete allocator satisfying the canonical structural protocol. Value: Writable allocator instance borrow retained only for the call. Count: Number of raw slots, including zero. Return: A distinct nonnull aligned base pointer or allocation/layout failure. Warning: The caller must establish each object lifetime before typed access.

Example

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

Free

pub unsafe fn Free<T, A>(
    Value: mut A&,
    Storage: mut T*,
    Count: usize
) -> void
    where A: Allocator

Releases raw storage previously acquired for exactly Count T slots. T: Exact complete slot type used for allocation. A: Compatible concrete allocator type. Value: Writable compatible allocator borrow retained only for the call. Storage: Exact base pointer, or null only when Count is zero. Count: Exact acquired slot count. Return: No value after allocation lifetime ends. Warning: No T object may remain live and no alias may be used afterward.

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