1
mirror of https://github.com/jlelse/GoBlog synced 2024-05-29 11:24:28 +00:00
GoBlog/pkgs/bufferpool/bufferPool.go
2022-03-16 08:28:03 +01:00

24 lines
304 B
Go

package bufferpool
import (
"bytes"
"sync"
)
var bufferPool = sync.Pool{
New: func() any {
return new(bytes.Buffer)
},
}
func Get() *bytes.Buffer {
return bufferPool.Get().(*bytes.Buffer)
}
func Put(bufs ...*bytes.Buffer) {
for _, buf := range bufs {
buf.Reset()
bufferPool.Put(buf)
}
}