mirror of
https://github.com/xjasonlyu/tun2socks.git
synced 2025-10-08 02:00:43 +08:00
fix buffer pool
This commit is contained in:
23
core/buffer_pool.go
Normal file
23
core/buffer_pool.go
Normal file
@@ -0,0 +1,23 @@
|
||||
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)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user