mirror of
https://github.com/cwinfo/yggdrasil-go.git
synced 2025-01-11 11:55:41 +00:00
18 lines
292 B
Go
18 lines
292 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])
|
||
|
}
|