kos/util/pool/buffer.go

23 lines
278 B
Go
Raw Permalink Normal View History

2023-04-23 17:57:36 +08:00
package pool
import (
"bytes"
"sync"
)
var (
bufferPool sync.Pool
)
func GetBuffer() *bytes.Buffer {
if v := bufferPool.Get(); v != nil {
return v.(*bytes.Buffer)
}
return bytes.NewBuffer([]byte{})
}
func PutBuffer(b *bytes.Buffer) {
b.Reset()
bufferPool.Put(b)
}