October 2015
Beginner to intermediate
400 pages
14h 44m
English
unsafe.Sizeof, Alignof, and Offsetof
The unsafe.Sizeof function reports the size in bytes
of the representation of its operand,
which may be an expression of any type; the expression is not
evaluated.
A call to Sizeof is a constant expression of type
uintptr,
so the result may be used as the dimension of an array
type, or to compute other constants.
import "unsafe" fmt.Println(unsafe.Sizeof(float64(0))) // "8"
Sizeof reports only the size of the fixed part of each data structure, like the pointer and length of a string, but not indirect parts like the contents of the string. Typical sizes for all non-aggregate Go types are shown below, though the exact sizes may vary by toolchain. For portability, we’ve ...
Read now
Unlock full access