Rust Memory Layout and Allocation

The same three-field struct takes 12 bytes when it keeps declaration order and 8 when the compiler picks the order. Option<&T> is 8 bytes like the pointer itself, with no tag, and a Vec keeps 24 bytes on the stack and its elements on the heap. Sizes were checked with size_of and the effect of removing allocations with criterion. The eighth post in a Rust study series.

November 17, 2026 · 18 min read