FILE / ScuroNeko/mtg

mtproto/bufferpool/bufferpool.go

Исходный файл и его история в репозитории.
FILE 96bb6fbe980fb64d82ae941161c5079a75f9d054
Files
mtg/mtproto/bufferpool/bufferpool.go
T
2018-07-02 09:15:03 +03:00

33 lines
408 B
Go

package bufferpool
import (
"bytes"
"sync"
)
const bufferPoolSize = 4 * 1024
var bufferPool sync.Pool
func Get() *bytes.Buffer {
buf := bufferPool.Get().(*bytes.Buffer)
buf.Reset()
return buf
}
func Return(buf *bytes.Buffer) {
bufferPool.Put(buf)
}
func init() {
bufferPool = sync.Pool{
New: func() interface{} {
buf := &bytes.Buffer{}
buf.Grow(bufferPoolSize)
return buf
},
}
}