Use bytes.Buffer pools for wrappers

This commit is contained in:
9seconds
2018-06-20 08:24:17 +03:00
parent 08ea80680c
commit 9ddf3e147c
2 changed files with 39 additions and 12 deletions
+27
View File
@@ -0,0 +1,27 @@
package wrappers
import (
"bytes"
"sync"
)
var bufPool sync.Pool
func getBuffer() *bytes.Buffer {
buf := bufPool.Get().(*bytes.Buffer)
buf.Reset()
return buf
}
func putBuffer(buf *bytes.Buffer) {
bufPool.Put(buf)
}
func init() {
bufPool = sync.Pool{
New: func() interface{} {
return &bytes.Buffer{}
},
}
}