mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-07 10:12:19 +00:00
3d12322103
* add mem pool * use mem pool * Update shared/memorypool/memorypool.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update shared/memorypool/memorypool.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> Co-authored-by: terence tsao <terence@prysmaticlabs.com>
28 lines
692 B
Go
28 lines
692 B
Go
package memorypool
|
|
|
|
import "sync"
|
|
|
|
// DoubleByteSlicePool represents the memory pool
|
|
// for 2d byte slices.
|
|
var DoubleByteSlicePool = new(sync.Pool)
|
|
|
|
// GetDoubleByteSlice retrieves the 2d byte slice of
|
|
// the desired size from the memory pool.
|
|
func GetDoubleByteSlice(size int) [][]byte {
|
|
rawObj := DoubleByteSlicePool.Get()
|
|
if rawObj == nil {
|
|
return make([][]byte, size)
|
|
}
|
|
byteSlice := rawObj.([][]byte)
|
|
if len(byteSlice) >= size {
|
|
return byteSlice[:size]
|
|
}
|
|
return append(byteSlice, make([][]byte, size-len(byteSlice))...)
|
|
}
|
|
|
|
// PutDoubleByteSlice places the provided 2d byte slice
|
|
// in the memory pool.
|
|
func PutDoubleByteSlice(data [][]byte) {
|
|
DoubleByteSlicePool.Put(data)
|
|
}
|