frostfs-api-go/util/signature/buffer.go
Dmitrii Stepanov ec0d0274fa [#3] signature: Add buffer pool
Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
2023-03-10 13:36:26 +03:00

29 lines
464 B
Go

package signature
import "sync"
const poolSliceMaxSize = 64 * 1024
var buffersPool = sync.Pool{
New: func() any {
return make([]byte, 0)
},
}
func newBufferFromPool(size int) []byte {
result := buffersPool.Get().([]byte)
if cap(result) < size {
result = make([]byte, size)
} else {
result = result[:size]
}
return result
}
func returnBufferToPool(buf []byte) {
if cap(buf) > poolSliceMaxSize {
return
}
buf = buf[:0]
buffersPool.Put(buf)
}