SystemAllocator

public struct SystemAllocator { /* private fields */ }

Allocator backed by libc malloc/free/realloc. Used as the default GlobalAllocator and by every collection that doesn't pick a custom allocator.

Memory Model

Stateless: the struct holds no fields. All bookkeeping lives in libc's heap. Cloning or copying the allocator has no effect on the heap state.

Initializers

public init()

Builds a stateless system allocator. No heap interaction occurs here.

ImplementsAllocator

Methods

public mutating func allocate(Layout) -> RawPointer?

Calls malloc(layout.size). Alignment beyond malloc's natural alignment (typically 16) is not honoured — types that need larger alignment should use a different allocator.

public mutating func deallocate(RawPointer, Layout)

Calls free(ptr). The layout argument is ignored — kept for protocol conformance; allocators that need it (arenas) use it.

public mutating func reallocate(RawPointer, Layout, Layout) -> RawPointer?

Calls realloc(ptr, newLayout.size). As with allocate, only malloc-natural alignment is guaranteed.

Defined in lang/std/memory/allocator.ks