std.sys - ZZ
Infallible machine information: platform identity, CPU count, memory, hostname. All queries return fallback values (empty string / 0) — never .err.
import std.sysPurpose
Section titled “Purpose”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.
Quickstart
Section titled “Quickstart”import std.sys
println(sys.os()) // linux / macos / windowsprintln(sys.arch()) // x86_64 / aarch64 / …println(sys.cpu_count()) // logical cores — size your worker poolprintln(sys.hostname())println(sys.total_mem()) // bytesprintln(sys.avail_mem()) // bytesError model
Section titled “Error model”All queries are infallible — empty string / 0 on unknown, never .err.
Gotchas
Section titled “Gotchas”cpu_countis 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.
Production patterns
Section titled “Production patterns”import std.sysimport std.task
// Size a worker pool to logical coresworkers := sys.cpu_count()for i in 0..workers { task.spawn(|_| { /* work */ })}
// Cache sizing from available memorycache_mb := sys.avail_mem() / (1024 * 1024) / 4 // quarter of avail memAPI reference
Section titled “API reference”6 entries. Signatures come from the compiler’s own FuncSig table, so they match the runtime exactly; descriptions come from the module guide.
See also
Section titled “See also”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