Created
October 13, 2019 02:23
-
-
Save lachlan-eagling/aff66b0b68fe69667aca9c15c607f92c to your computer and use it in GitHub Desktop.
Blog - Anatomy of a Struct (Unoptimised Example)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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