Skip to content

Incorrect size of [][]string #16

Description

@Dmitriy-Kulagin
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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions