-
Book Overview & Buying
-
Table Of Contents
Mastering Distributed Observability in Rust
By :
A central choice in any Rust program is where data lives: stack or heap. The choice affects latency, cache behavior, and how allocations appear in your telemetry. Rust's rules make that choice explicit and traceable.
The stack is an extremely efficient memory area that behaves like a stack of plates (LIFO). Allocation is little more than moving a pointer; deallocation is just as quick. However, stacks are typically limited to a few megabytes per thread, so they're unsuitable for large data structures. Each thread has its own stack, which removes the need for synchronization between threads.
Scalar types, aggregates, and user-defined types with known, fixed sizes are stack-allocated at compile time:
// Scalar types, aggregates, and user-defined types with known, fixed sizes
let number: i32 = 42; // 4 bytes
let flag: bool = true; // 1 byte
let character...