You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
445 B
Go
32 lines
445 B
Go
package utils
|
|
|
|
import (
|
|
"bytes"
|
|
"sync"
|
|
)
|
|
|
|
const (
|
|
TooBigBlockSize = 1024 * 1024 * 4
|
|
)
|
|
|
|
var (
|
|
bytesBufferPool = sync.Pool{
|
|
New: func() interface{} {
|
|
return &bytes.Buffer{}
|
|
},
|
|
}
|
|
)
|
|
|
|
func BytesBufferGet() (data *bytes.Buffer) {
|
|
data = bytesBufferPool.Get().(*bytes.Buffer)
|
|
data.Reset()
|
|
return data
|
|
}
|
|
|
|
func BytesBufferPut(data *bytes.Buffer) {
|
|
if data == nil || data.Len() > TooBigBlockSize {
|
|
return
|
|
}
|
|
bytesBufferPool.Put(data)
|
|
}
|