mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2025-04-29 06:35:07 +03:00
Merge branch 'future' into develop-future
This commit is contained in:
commit
fdb296047b
28 changed files with 1049 additions and 880 deletions
|
@ -1,21 +0,0 @@
|
|||
//+build mobile
|
||||
|
||||
package util
|
||||
|
||||
import "runtime/debug"
|
||||
|
||||
func init() {
|
||||
debug.SetGCPercent(25)
|
||||
}
|
||||
|
||||
// GetBytes always returns a nil slice on mobile platforms.
|
||||
func GetBytes() []byte {
|
||||
return nil
|
||||
}
|
||||
|
||||
// PutBytes does literally nothing on mobile platforms.
|
||||
// This is done rather than keeping a free list of bytes on platforms with memory constraints.
|
||||
// It's needed to help keep memory usage low enough to fall under the limits set for e.g. iOS NEPacketTunnelProvider apps.
|
||||
func PutBytes(bs []byte) {
|
||||
return
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
//+build !mobile
|
||||
|
||||
package util
|
||||
|
||||
import "sync"
|
||||
|
||||
// This is used to buffer recently used slices of bytes, to prevent allocations in the hot loops.
|
||||
var byteStore = sync.Pool{New: func() interface{} { return []byte(nil) }}
|
||||
|
||||
// GetBytes returns a 0-length (possibly nil) slice of bytes from a free list, so it may have a larger capacity.
|
||||
func GetBytes() []byte {
|
||||
return byteStore.Get().([]byte)[:0]
|
||||
}
|
||||
|
||||
// PutBytes stores a slice in a free list, where it can potentially be reused to prevent future allocations.
|
||||
func PutBytes(bs []byte) {
|
||||
byteStore.Put(bs)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue