Last active
April 16, 2022 16:52
-
-
Save kodelint/a7d1f0f498d536dd6c515f6cded41889 to your computer and use it in GitHub Desktop.
Golang Memory Allocation Verifier
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" | |
import "unsafe" | |
type TerraformResource struct { | |
Cloud string // 16 bytes | |
Name string // 16 bytes | |
HaveDSL bool // 1 byte | |
PluginVersion string // 16 bytes | |
IsVersionControlled bool // 1 byte | |
TerraformVersion string // 16 bytes | |
ModuleVersionMajor int32 // 4 bytes | |
} | |
func main() { | |
var d TerraformResource | |
d.Cloud = "aws" | |
d.Name = "ec2" | |
d.HaveDSL = true | |
d.PluginVersion = "3.64" | |
d.TerraformVersion = "1.1" | |
d.ModuleVersionMajor = 1 | |
d.IsVersionControlled = true | |
fmt.Println("==============================================================") | |
fmt.Printf("Total Memory Usage StructType:d %T => [%d]\n", d, unsafe.Sizeof(d)) | |
fmt.Println("==============================================================") | |
fmt.Printf("Cloud Field StructType:d.Cloud %T => [%d]\n", d.Cloud, unsafe.Sizeof(d.Cloud)) | |
fmt.Printf("Name Field StructType:d.Name %T => [%d]\n", d.Name, unsafe.Sizeof(d.Name)) | |
fmt.Printf("HaveDSL Field StructType:d.HaveDSL %T => [%d]\n", d.HaveDSL, unsafe.Sizeof(d.HaveDSL)) | |
fmt.Printf("PluginVersion Field StructType:d.PluginVersion %T => [%d]\n", d.PluginVersion, unsafe.Sizeof(d.PluginVersion)) | |
fmt.Printf("ModuleVersionMajor Field StructType:d.IsVersionControlled %T => [%d]\n", d.IsVersionControlled, unsafe.Sizeof(d.IsVersionControlled)) | |
fmt.Printf("TerraformVersion Field StructType:d.TerraformVersion %T => [%d]\n", d.TerraformVersion, unsafe.Sizeof(d.TerraformVersion)) | |
fmt.Printf("ModuleVersionMajor Field StructType:d.ModuleVersionMajor %T => [%d]\n", d.ModuleVersionMajor, unsafe.Sizeof(d.ModuleVersionMajor)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment