Spaces:
Sleeping
Sleeping
File size: 459 Bytes
da590a7 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | package utils
import (
"bytes"
"sync"
)
// BufferPool is a pool of bytes.Buffer to reduce allocation pressure.
var BufferPool = sync.Pool{
New: func() interface{} {
return new(bytes.Buffer)
},
}
// GetBuffer retrieves a buffer from the pool.
func GetBuffer() *bytes.Buffer {
return BufferPool.Get().(*bytes.Buffer)
}
// PutBuffer resets the buffer and returns it to the pool.
func PutBuffer(buf *bytes.Buffer) {
buf.Reset()
BufferPool.Put(buf)
}
|