100-go-mistakes/src/12-optimizations/96-reduce-allocations/sync-pool/main.go
2024-01-25 11:27:46 +01:00

28 lines
322 B
Go

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