AlgoMaster Logo

Sizeof, Alignof & Offsetof

Last Updated: May 22, 2026

Low Priority
11 min read

The unsafe package gives you three compile-time functions that report how Go lays out values in memory: Sizeof, Alignof, and Offsetof. They don't read or write memory and they don't allocate. They tell you, at build time, how many bytes a type occupies, how that type wants to be aligned, and where each field of a struct sits relative to the start of the struct. This chapter explains what each one returns, how struct padding works, and how reordering fields can shrink a struct used in a hot path.

Premium Content

Subscribe to unlock full access to this content and more premium articles.