Skip to content

Instantly share code, notes, and snippets.

@lachlan-eagling
Created October 13, 2019 02:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lachlan-eagling/aff66b0b68fe69667aca9c15c607f92c to your computer and use it in GitHub Desktop.
Save lachlan-eagling/aff66b0b68fe69667aca9c15c607f92c to your computer and use it in GitHub Desktop.
Blog - Anatomy of a Struct (Unoptimised Example)
package main
import (
"fmt"
"unsafe"
)
type Post struct {
published bool // 1 byte
title string // 16 Bytes
content string // 16 Bytes
likes int16 // 2 bytes
// 35 bytes total, 13 bytes padding
}
func main() {
fmt.Printf("Sizeof Post: %d\n", unsafe.Sizeof(Post{}))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment