5
0
mirror of https://github.com/cwinfo/yggdrasil-go.git synced 2025-01-11 07:15:42 +00:00
yggdrasil-go/src/core/pool.go
2023-05-21 12:49:49 -05:00

18 lines
313 B
Go

package core
import "sync"
var bytePool = sync.Pool{New: func() interface{} { return []byte(nil) }}
func allocBytes(size int) []byte {
bs := bytePool.Get().([]byte)
if cap(bs) < size {
bs = make([]byte, size)
}
return bs[:size]
}
func freeBytes(bs []byte) {
bytePool.Put(bs[:0]) //nolint:staticcheck
}