Add byte buffer pool
This commit is contained in:
parent
d92a439c54
commit
dd71e0907a
1 changed files with 27 additions and 0 deletions
27
strmangle/buf_pool.go
Normal file
27
strmangle/buf_pool.go
Normal 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)
|
||||
}
|
Loading…
Reference in a new issue