Consider the following code
package main
import (
\"fmt\"
)
func main() {
x := []byte(\"a\")
fmt.Println(x)
fmt.Println(cap(x) == cap([]byt
The explanation is, like bradfitz point in github, if you don't use make
to create a slice, the compiler will use the cap it believes convenient. Creating multiple slices in different versions, or even the same, can result on slices of different capacities.
In short, if you need a concrete capacity, use make([]byte, len, cap)
. Otherwise you can't trust on a fixed capacity.