Consider the following excerpt from Prometheus source code:
func (ls Labels) String() string {
var bytea [1024]byte // On stack to avoid memory allocation while building the output.
b := bytes.NewBuffer(bytea[:0])
...
}
How exactly does defining byte array bytea [1024]byte and using its zero-length slicing result bytea[:0] to create new *bytes.Buffer help to avoid memory allocation?
bytes.NewBufferdocs as well, what isn't clear in this use case?make([]byte, 0, 1024), I don't need an array