mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2025-04-29 14:45:07 +03:00
20 lines
472 B
Go
20 lines
472 B
Go
package yggdrasil
|
|
|
|
import "sync"
|
|
|
|
// Used internally to reduce allocations in the hot loop
|
|
// I.e. packets being switched or between the crypto and the switch
|
|
// For safety reasons, these must not escape this package
|
|
var pool = sync.Pool{New: func() interface{} { return []byte(nil) }}
|
|
|
|
func pool_getBytes(size int) []byte {
|
|
bs := pool.Get().([]byte)
|
|
if cap(bs) < size {
|
|
bs = make([]byte, size)
|
|
}
|
|
return bs[:size]
|
|
}
|
|
|
|
func pool_putBytes(bs []byte) {
|
|
pool.Put(bs)
|
|
}
|