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

DefaultAllocator

Supplies the stateless target-selected default raw-storage allocator.

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.

DefaultAllocator

pub struct DefaultAllocator

Supplies the stateless target-selected default raw-storage allocator.

Every instance belongs to one compatibility domain, so a live instance may free storage acquired through another. Construction allocates nothing. The Linux/POSIX leaf delegates to posix_memalign and free; callers still own all object-lifetime operations in that storage.

Example

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

DefaultAllocator.Allocate

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

Acquires one distinct aligned allocation, including for zero bytes. StorageLayout: Exact valid layout produced by Layout. Return: Nonnull writable bytes or a stable portable allocation error. Warning: The caller must start any typed lifetime explicitly and later free the exact base/layout through a compatible allocator instance.

DefaultAllocator.Free

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

Ends one compatible allocation lifetime. Storage: Exact base pointer, or null only for default(Layout). StorageLayout: Exact acquisition layout for nonnull storage. Return: No value after target storage release. Warning: Every object lifetime must already be ended and no alias may be used after this call.

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