[go-nuts] Re: Confused about heap usage for empty slices

2022-09-08 Thread Mathew Murphy
Thanks. So basically, there's no memory benefit or performance benefit to using nil slices over empty slices -- it's ultimately just a matter of how you want them to serialize JSON or get written to databases? mathew On Wednesday, September 7, 2022 at 6:56:33 PM UTC-5 k...@google.com wrote: >

[go-nuts] Confused about heap usage for empty slices

2022-09-07 Thread mathew murphy
Running this: emptyslice := []string{} sh := (*reflect.SliceHeader)(unsafe.Pointer(&emptyslice)) fmt.Printf("empty slice cap = %d\n", sh.Cap) fmt.Printf("empty slice len = %d\n", sh.Len) fmt.Printf("empty slice uintptr = %v\n", sh.Data) Output: empty slice cap = 0 empty slice len = 0 emp