How does struct field ordering affect memory layout in Go and Rust?
It tests alignment, padding, and compiler layout knowledge. A strong answer explains that alignment inserts padding, Go and Rust keep declared order, and reordering by size can shrink size. Red flag: saying order is irrelevant or that compiler auto-packs.
It tests understanding of data structure alignment, padding, and layout rules in Go and Rust. A strong answer defines alignment as requiring each field to start at an address multiple of its type size, explains compilers insert padding to satisfy this, notes both languages preserve source order, and walks through a concrete struct where placing an int64 before a bool versus after changes total size from 24 bytes to 16 bytes on 64-bit systems.
Read the original → Wikipedia: Data structure alignment
- #go
- #rust
- #memory
- #alignment
- #structs
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.