update core

This commit is contained in:
Jason
2020-08-04 18:27:14 +08:00
parent 70bb65de03
commit 34377270a3
228 changed files with 35 additions and 17 deletions

28
core/buffer_pool.go Normal file → Executable file
View File

@@ -4,20 +4,32 @@ import (
"sync"
)
const defaultBufferSize = 2 * 1024
var pool *sync.Pool
var bufPool = sync.Pool{New: func() interface{} { return make([]byte, defaultBufferSize) }}
const BufSize = 2 * 1024
func newBytes(size int) []byte {
if size <= defaultBufferSize {
return bufPool.Get().([]byte)
func SetBufferPool(p *sync.Pool) {
pool = p
}
func NewBytes(size int) []byte {
if size <= BufSize {
return pool.Get().([]byte)
} else {
return make([]byte, size)
}
}
func freeBytes(b []byte) {
if len(b) >= defaultBufferSize {
bufPool.Put(b)
func FreeBytes(b []byte) {
if len(b) >= BufSize {
pool.Put(b)
}
}
func init() {
SetBufferPool(&sync.Pool{
New: func() interface{} {
return make([]byte, BufSize)
},
})
}