You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
IsaacShelton edited this page Mar 21, 2022
·
1 revision
packed
By default, structures contain padding in order to improve access performance.
The packed keyword can be used to disable struct padding.
packed struct MyFileHeader (magic ushort, version uint, offset1, offset2 usize)
This is good for values that will be stored on disk or sent over the network.
Example
import basics
// Size difference between packed versus unpacked.
// This is usually only apparent when field types
// are non-uniform.
struct One (a int, b long, c int)
packed struct Two (a int, b long, c int)
func main {
printf("sizeof One == %zu\n", sizeof One)
printf("sizeof Two == %zu\n", sizeof Two)
}