mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2025-04-30 07:05:06 +03:00
eliminate most sync.Pool use, gives a safer but slightly slower interface
This commit is contained in:
parent
9d0969db2b
commit
6d89570860
14 changed files with 53 additions and 96 deletions
20
src/yggdrasil/pool.go
Normal file
20
src/yggdrasil/pool.go
Normal file
|
@ -0,0 +1,20 @@
|
|||
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)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue