Skip to content

std.sys - ZZ

Infallible machine information: platform identity, CPU count, memory, hostname. All queries return fallback values (empty string / 0) — never .err.

import std.sys

std.sys reports platform identity and resources. Use cpu_count for task.spawn fan-out, total_mem/avail_mem for cache sizing and diagnostics headers.

import std.sys
println(sys.os()) // linux / macos / windows
println(sys.arch()) // x86_64 / aarch64 / …
println(sys.cpu_count()) // logical cores — size your worker pool
println(sys.hostname())
println(sys.total_mem()) // bytes
println(sys.avail_mem()) // bytes

All queries are infallible — empty string / 0 on unknown, never .err.

  • cpu_count is logical cores — size worker pools accordingly, not 1:1 with physical cores.
  • Memory values are bytes — divide by 1024/1024 for MiB.
  • Fallbacks on unknown platforms — don’t assert specific values in tests.
import std.sys
import std.task
// Size a worker pool to logical cores
workers := sys.cpu_count()
for i in 0..workers {
task.spawn(|_| { /* work */ })
}
// Cache sizing from available memory
cache_mb := sys.avail_mem() / (1024 * 1024) / 4 // quarter of avail mem

6 entries. Signatures come from the compiler’s own FuncSig table, so they match the runtime exactly; descriptions come from the module guide.

Function Signature Description
std.sys.arch arch() -> str “x86_64” / “aarch64” / …
std.sys.avail_mem avail_mem() -> int Available RAM, bytes
std.sys.cpu_count cpu_count() -> int Logical cores
std.sys.hostname hostname() -> str Host name
std.sys.os os() -> str “linux” / “macos” / “windows”
std.sys.total_mem total_mem() -> int Total RAM, bytes
  • std.env — Environment variables and the surrounding host environment.
  • std.args — argv access and the flag parser: booleans, integers, strings and subcommands.
  • std.process — Spawning, waiting on and signalling child processes.
  • std.log — Log levels, sinks and spans for structured logging.
  • std.path — Pure lexical path manipulation: join, split, extension and normalisation.
  • std.cell — Shared mutable slots for lock-free hand-off between green threads.

Full index: API reference · Standard library