Skip to content

Instantly share code, notes, and snippets.

View romanitalian's full-sized avatar
🎯
Focusing

roman romadin romanitalian

🎯
Focusing
View GitHub Profile
linters-settings:
maligned:
# print struct with more effective memory layout or not, false by default
suggest-new: true
// $ maligned .
/Users/rmn/wks/src/github.com/romanitalian/alignment/main.go:8:10: struct of size 12 could be 8
// $ aligncheck .
github.com/romanitalian/alignment: /Users/rmn/wks/src/github.com/romanitalian/alignment/main.go:8:6: struct Foo could have size 8 (currently 12)
type Foo struct {
aaa [2]bool
bbb int32
ccc [2]bool
}
type Bar struct {
aaa [2]bool
ccc [2]bool
bbb int64
package main
import (
"fmt"
"unsafe"
)
type Foo struct {
aaa [2]bool // offset of bytes: 0
bbb int32 // offset of bytes: 4
type Foo struct {
aaa [2]bool // 2 bytes
ccc [2]bool // 2 bytes
bbb int32 // 4 bytes
}
type Foo struct {
aaa [2]bool // 2 bytes
bbb int32 // 4 bytes
ccc [2]bool // 2 bytes
}
type Foo struct {
aaa bool
bbb int64
ссс bool
ddd bool
}
type Foo struct {
aaa bool // 1
bbb int32 // 4 (max)
ссс bool // 1
ddd bool // 1
}
type Foo2 struct {
aaa int32 // 4
bbb int32 // 4
ccc int32 // 4
}