mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-09-01 02:14:02 +03:00
Add bytesrwc
This commit is contained in:
@@ -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
|
||||
},
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user