5
0
mirror of https://github.com/cwinfo/yggdrasil-go.git synced 2025-01-11 09:35:41 +00:00
yggdrasil-go/src/core/pool.go

18 lines
313 B
Go
Raw Normal View History

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) {
2023-05-21 17:49:49 +00:00
bytePool.Put(bs[:0]) //nolint:staticcheck
}