mirror of
https://github.com/CPunch/gopenfusion.git
synced 2024-11-23 15:50:10 +00:00
22 lines
350 B
Go
22 lines
350 B
Go
package protocol
|
|
|
|
import (
|
|
"bytes"
|
|
"sync"
|
|
)
|
|
|
|
var allocator = &sync.Pool{
|
|
New: func() any { return new(bytes.Buffer) },
|
|
}
|
|
|
|
// grabs a *bytes.Buffer from the pool
|
|
func GetBuffer() *bytes.Buffer {
|
|
return allocator.Get().(*bytes.Buffer)
|
|
}
|
|
|
|
// returns a *bytes.Buffer to the pool
|
|
func PutBuffer(buf *bytes.Buffer) {
|
|
buf.Reset()
|
|
allocator.Put(buf)
|
|
}
|