mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-08-31 15:34:01 +03:00
FILE / ScuroNeko/mtg
mtproto/bufferpool.go
Исходный файл и его история в репозитории.
33 lines
417 B
Go
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
|
|
},
|
|
}
|
|
}
|