forked from TrueCloudLab/frostfs-api-go
[#3] signature: Add buffer pool
Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
parent
73fde0e37c
commit
ec0d0274fa
5 changed files with 67 additions and 58 deletions
29
util/signature/buffer.go
Normal file
29
util/signature/buffer.go
Normal file
|
@ -0,0 +1,29 @@
|
|||
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)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue