Skip to content

Instantly share code, notes, and snippets.

@TylerBrock
Created October 27, 2024 20:36
Show Gist options
  • Save TylerBrock/93aebe1dd2659a094c6565a6fea06895 to your computer and use it in GitHub Desktop.
Save TylerBrock/93aebe1dd2659a094c6565a6fea06895 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"unsafe"
)
type Key struct { // 32 + 12 = 44 bytes
t bool // 1 byte + 7 bytes padding
id string // 16 bytes + 12 bytes data for ObjectID values
hash uint32 // 4 bytes + 4 bytes padding
}
type OptimizedKey struct {
id string // 16 bytes + 12 bytes data for ObjectID values
hash uint32 // 4 bytes
t bool // 1 byte + 1 bytes padding
}
type Sum uint64 // 8 bytes
func main() {
old := Key{true, "", 0}
opt := OptimizedKey{"", 0, true}
fmt.Println(unsafe.Sizeof(old), unsafe.Sizeof(opt))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment