Summarize the size of all memory, excluding the garbage collector and other overhead. For instance,
package main import ( "fmt" "unsafe" ) type ASDF struct { A uint64 B uint64 C uint64 D uint64 E uint64 F string } func (s *ASDF) size() int { size := int(unsafe.Sizeof(*s)) size += len(sF) return size } func sizeASDF(s []ASDF) int { size := 0 s = s[:cap(s)] size += cap(s) * int(unsafe.Sizeof(s)) for i := range s { size += (&s[i]).size() } return size } func main() { a := []ASDF{} b := ASDF{} bA = 1 bB = 2 bC = 3 bD = 4 bE = 5 bF = "ASrtertetetetetetetDF" fmt.Println((&b).size()) a = append(a, b) c := ASDF{} cA = 10 cB = 20 cC = 30 cD = 40 cE = 50 cF = "ASetDF" fmt.Println((&c).size()) a = append(a, c) fmt.Println(len(a)) fmt.Println(cap(a)) fmt.Println(sizeASDF(a)) }
Output:
69 54 2 2 147
http://play.golang.org/p/5z30vkyuNM
source share