Skip to content

Instantly share code, notes, and snippets.

@lachlan-eagling
Created October 13, 2019 02:25
Show Gist options
  • Select an option

  • Save lachlan-eagling/5a46d82fac859dc929d2be6fc5248f64 to your computer and use it in GitHub Desktop.

Select an option

Save lachlan-eagling/5a46d82fac859dc929d2be6fc5248f64 to your computer and use it in GitHub Desktop.
Blog - Anatomy of a Struct (Optimised Example)
package main
import (
"fmt"
"unsafe"
)
type OptimisedPost struct {
title string // 16 Bytes
content string // 16 Bytes
likes int16 // 2 bytes
published bool // 1 byte
// 35 bytes total
}
func main() {
fmt.Printf("Sizeof OptimisedPost: %d\n", unsafe.Sizeof(OptimisedPost{}))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment