29 lines
520 B
Go
29 lines
520 B
Go
package buf
|
|
|
|
import (
|
|
"sync"
|
|
)
|
|
|
|
// atomicBuffer pool to reduce GC
|
|
var atoBuffers = sync.Pool{
|
|
// New is called when a new instance is needed
|
|
New: func() interface{} {
|
|
return new(atomicBuffer)
|
|
},
|
|
}
|
|
|
|
// GetBuffer fetches a atomicBuffer from the pool
|
|
func GetAtoBuffer() AtomicBuffers {
|
|
return atoBuffers.Get().(AtomicBuffers)
|
|
}
|
|
|
|
// PutBuffer returns a atomicBuffer to the pool
|
|
func PutAtoBuffer(buf AtomicBuffers) {
|
|
bufPtr, ok := buf.(*atomicBuffer)
|
|
if !ok {
|
|
return
|
|
}
|
|
bufPtr.Reset()
|
|
atoBuffers.Put(bufPtr)
|
|
}
|