I'm learning golang, and confused about the capacity in slice.
For example arr := make([]float64, 5, 10)
I have an array of 5 values, and its capacity is 10. If I assign a value to 8th position, the compiler would throw an error index is out of range. If I grow a slice, but it creates a new slice (see the doc that I copied from the official go language).
Here's the slice doc:
"Slicing does not copy the slice's data. It creates a new slice value that points to the original array." "To increase the capacity of a slice one must create a new, larger slice and copy the contents of the original slice into it. "
So what's the purpose of capacity?
Thanks