100-go-mistakes/12-optimizations/96-reduce-allocations/sync-pool/main.go
2021-12-27 15:56:17 +01:00

24 lines
296 B
Go

package main
import (
"io"
"sync"
)
var pool = sync.Pool{
New: func() any {
return make([]byte, 1024)
},
}
func write(w io.Writer) {
buffer := pool.Get().([]byte)
buffer = buffer[:0]
defer pool.Put(buffer)
getResponse(buffer)
_, _ = w.Write(buffer)
}
func getResponse([]byte) {
}