36 lines
498 B
Go
Raw Normal View History

2020-08-13 17:34:41 +02:00
package utils
import (
"bytes"
"sync"
)
var (
bytesBufferPool = sync.Pool{
New: func() interface{} {
return &bytes.Buffer{}
},
}
bytesBufferChan = make(chan *bytes.Buffer, 10)
)
func BytesBufferGet() (data *bytes.Buffer) {
select {
case data = <-bytesBufferChan:
default:
data = bytesBufferPool.Get().(*bytes.Buffer)
}
data.Reset()
return data
}
func BytesBufferPut(data *bytes.Buffer) {
select {
case bytesBufferChan <- data:
default:
bytesBufferPool.Put(data)
}
}