1 Star 0 Fork 0

jmesyan / impetus

Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
Clone or Download
protocol.go 735 Bytes
Copy Edit Raw Blame History
jmesyan authored 2020-12-19 20:39 . go mod 优化
package protocol
import (
"bytes"
"github.com/smallnest/rpcx/util"
"sync"
)
var (
bufferPool = util.NewLimitedPool(512, 4096)
sPool = &sync.Pool{
New: func() interface{} {
return &bytes.Buffer{}
},
}
)
func GetPoolMsg() *bytes.Buffer {
return sPool.Get().(*bytes.Buffer)
}
func FreePoolMsg(buf *bytes.Buffer) {
sPool.Put(buf)
}
func GetPoolBuffer(size int) *[]byte {
return bufferPool.Get(size)
}
func FreePoolBuffer(buf *[]byte) {
bufferPool.Put(buf)
}
var poolUint32Data = sync.Pool{
New: func() interface{} {
data := make([]byte, 4)
return &data
},
}
func GetUint32PoolData() *[]byte {
return poolUint32Data.Get().(*[]byte)
}
func PutUint32PoolData(buffer *[]byte) {
poolUint32Data.Put(buffer)
}
Go
1
https://gitee.com/jmesyan/impetus.git
git@gitee.com:jmesyan/impetus.git
jmesyan
impetus
impetus
v1.1.4

Search

53164aa7 5694891 3bd8fe86 5694891