FILE / ScuroNeko/mtg

mtproto/bufferpool.go

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

33 lines
417 B
Go

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