gh-ost/vendor/github.com/siddontang/go-mysql/utils/bytes_buffer_pool.go
Tim Vaillancourt 8c81334fad Use go modules
2020-08-13 17:34:41 +02:00

36 lines
498 B
Go

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)
}
}