You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
cnt := 1000
ss := make([][]string, cnt, cnt) // len = cap = 1000
s := make([]string, 1, 1) // len = cap = 1 : slice header = 24
s[0] = "1234567890" // len = 10 symbols/bytes, string header = 16
fmt.Println(size.Of(s)) // 50 = 10 + 16 + 24
for i := range ss {
ss[i] = s // the same value for all values in upper slice
}
fmt.Println(size.Of(ss)) // 74 !!!
74 bytes to store slice of 1000 elements?
Underlying array of upper slice should have (as I understand) 1000 pointers to s. So, the expected result have to be: 50(s) + 24(upper slice header) + 8(per pointer)*cnt = 8074.
The text was updated successfully, but these errors were encountered:
Probably I'm not right. Elements of underlying array of upper slice of [][]string have to be slice headers.
So, probably right result should be 26(string+header)+24(upper slice header)+24*1000(upper slice elements)=24050.
8074 can be correct for []*[]string with 1000 pointers to the same slice of strings: []string{"1234567890"}.
>>>>>> size.go:37
case reflect.Slice:
-- // return 0 if this node has been visited already
++ // return slice header size if this node has been visited already
if cache[v.Pointer()] {
-- return 0
++ return int(v.Type().Size())
}
74 bytes to store slice of 1000 elements?
Underlying array of upper slice should have (as I understand) 1000 pointers to
s
. So, the expected result have to be: 50(s
) + 24(upper slice header) + 8(per pointer)*cnt
= 8074.The text was updated successfully, but these errors were encountered: