Hasty Briefsbeta

Bilingual

How (memory) safe is Zig? (2021)

a year ago
  • #zig
  • #memory-safety
  • #rust
  • Zig's memory safety is often compared to C or Rust, but it doesn't match Rust's systematic prevention of memory unsafety.
  • Zig introduces adhoc runtime checks (e.g., bounds checking, null pointer disallowing) but lacks composable compile-time proofs like Rust.
  • Zig improves over C with features like allocator APIs for detecting use-after-free, generics, and safer defaults.
  • Memory safety bugs in Zig are common, especially in complex projects, unlike Rust, which significantly reduces such issues.
  • Zig's future may lie in niches like sandboxed plugins (e.g., WASM) where its small binary size and low memory usage are advantageous.
  • Rust's memory safety is appealing for high-performance, secure systems, but managed languages (e.g., Java, C#) are improving in performance.
  • Zig's comptime mechanism offers unique compile-time specialization possibilities, inspiring future language design innovations.