News for hackers. Stuff that matters.
Re:Simple techniques to optimise Go programs by capo64 on Tuesday June 18, 2019 @12:52PM (#20215140)
The make function takes the type, length and capacity. If you don’t supply capacity, it defaults to length. So if you want to use append, do something like: make([]int, 0, length)

That will allocate a slice that can fit length ints but has a length of 0 (so append starts at index 0).

You can call len(slice) and cap(slice) to see the difference, but append will insert an element at index len(slice), growing the capacity if necessary

Re:Simple techniques to optimise Go programs by astockwell on Tuesday June 18, 2019 @01:07PM (#20215381)
Ahh thanks for the great explanation! Love HN.