zeroclaw / pkg /utils /pool.go
personalbotai
Move picoclaw_space to root for Hugging Face Spaces deployment
c1dcaaa
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)
}