forked from TrueCloudLab/frostfs-api-go
29 lines
464 B
Go
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)
|
|
}
|