1
mirror of https://github.com/jlelse/GoBlog synced 2024-06-01 10:54:27 +00:00
GoBlog/pkgs/bufferpool/bufferPool.go

24 lines
312 B
Go

package bufferpool
import (
"bytes"
"sync"
)
var bufferPool = sync.Pool{
New: func() interface{} {
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)
}
}