mirror of
https://github.com/xjasonlyu/tun2socks.git
synced 2025-10-07 09:41:09 +08:00
24 lines
387 B
Go
24 lines
387 B
Go
package core
|
|
|
|
import (
|
|
"sync"
|
|
)
|
|
|
|
const defaultBufferSize = 2 * 1024
|
|
|
|
var bufPool = sync.Pool{New: func() interface{} { return make([]byte, defaultBufferSize) }}
|
|
|
|
func newBytes(size int) []byte {
|
|
if size <= defaultBufferSize {
|
|
return bufPool.Get().([]byte)
|
|
} else {
|
|
return make([]byte, size)
|
|
}
|
|
}
|
|
|
|
func freeBytes(b []byte) {
|
|
if len(b) >= defaultBufferSize {
|
|
bufPool.Put(b)
|
|
}
|
|
}
|