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

18 lines
292 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) {
bytePool.Put(bs[:0])
}