mirror of
https://github.com/cwinfo/yggdrasil-go.git
synced 2025-01-11 07:15:42 +00:00
18 lines
313 B
Go
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
|
|
}
|