Under heavy development. This site describes the intended 1.0 language. Current features and performance vary. Development status
Sn50SnThe SnAPI programming language
Development · Evolving reference

PosixMemory

POSIX/Linux `ENOMEM` used only by the selected translation leaf.

Sn is under heavy development. This reference includes the intended 1.0 design; features may be incomplete in the current compiler. Read the status →

Module std.posix.memory

import std.posix.memory;

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

PosixOutOfMemory

pub const PosixOutOfMemory: i32;

POSIX/Linux ENOMEM used only by the selected translation leaf.

PosixInvalidArgument

pub const PosixInvalidArgument: i32;

POSIX/Linux EINVAL used only by the selected translation leaf.

<

pub fn<.C> posix_memalign(
    [abi.NonNull]
    [abi.NoCapture]
    Output: mut (mut void*)*,
    Alignment: usize,
    ByteSize: usize
) -> i32;

Acquires aligned raw storage through the selected POSIX C runtime. Output: Nonnull writable pointer receiving the returned allocation base. Alignment: Power-of-two alignment and multiple of sizeof(void*). ByteSize: Requested storage extent; zero has implementation-defined identity. Return: Zero on success, EINVAL for invalid alignment, or ENOMEM on failure. Pre: Safety: Output designates one live writable void* object for the call. Pre: Safety: the selected libc uses the declared void**, size_t, size_t ABI and no foreign unwind crosses into Sn. Warning: May allocate, lock, and mutate process allocator state.

Example

module example.posix_memalign;
from std.posix.memory import PosixOutOfMemory, free, posix_memalign;
fn Main() -> i32 {
    var Storage: mut void* = null;
    unsafe {
        let Status = posix_memalign(&Storage, 16, 64);
        if Status == PosixOutOfMemory {
            return 1;
        }
        if Status != 0 { return 2; }
        free(Storage);
    }
    return 0;
}

<

pub fn<.C> free([abi.NoCapture] Storage: mut void*) -> void;

Releases one allocation acquired by the selected C allocator. Storage: Exact allocation base, or null for a no-op. Return: No value after release. Pre: Safety: nonnull Storage is a live compatible allocation base with no live objects or later aliases; the call occurs exactly once. Pre: Safety: the selected libc matches the declared void* ABI and no foreign unwind crosses into Sn. Warning: Ends the allocation lifetime and may lock or mutate allocator state.

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