1 Star 0 Fork 0

liuqiaosz/gokits

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
buffpools.go 517 Bytes
一键复制 编辑 原始数据 按行查看 历史
rod_liu 提交于 2020-06-15 18:42 +08:00 . fitst commit
package utils
import (
"bytes"
"sync"
)
type byteBuffPool struct {
pools *sync.Pool
}
var pool *byteBuffPool
func GetBuffPool() *byteBuffPool {
if nil == pool {
pool = &byteBuffPool{
}
pool.pools = &sync.Pool{
New: func() interface{} {
return bytes.NewBuffer(make([]byte, 4096))
},
}
}
return pool
}
func (p *byteBuffPool) Get() *bytes.Buffer {
buff := p.pools.Get().(*bytes.Buffer)
buff.Reset()
return buff
}
func (p *byteBuffPool) Put(b *bytes.Buffer) {
b.Reset()
p.pools.Put(b)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/liuqiaosz/gokits.git
git@gitee.com:liuqiaosz/gokits.git
liuqiaosz
gokits
gokits
740bfc494305

搜索帮助