Add byte buffer pool

This commit is contained in:
Patrick O'brien 2016-08-13 17:49:39 +10:00
parent d92a439c54
commit dd71e0907a

27
strmangle/buf_pool.go Normal file
View file

@ -0,0 +1,27 @@
package strmangle
import (
"bytes"
"sync"
)
var bufPool = sync.Pool{
New: newBuffer,
}
func newBuffer() interface{} {
return &bytes.Buffer{}
}
// GetBuffer retrieves a buffer from the buffer pool
func GetBuffer() *bytes.Buffer {
buf := bufPool.Get().(*bytes.Buffer)
buf.Reset()
return buf
}
// PutBuffer back into the buffer pool
func PutBuffer(buf *bytes.Buffer) {
bufPool.Put(buf)
}