Add bytesrwc

This commit is contained in:
9seconds
2018-07-02 10:33:25 +03:00
parent b74cc8d3ea
commit 2c387cc213
3 changed files with 54 additions and 6 deletions
+32
View File
@@ -0,0 +1,32 @@
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
},
}
}