1 Star 0 Fork 1

leminewx/gokit

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
bytes_buffer_pool.go 544 Bytes
一键复制 编辑 原始数据 按行查看 历史
leminewx 提交于 2025-07-28 22:34 +08:00 . v0.6.0.0
package pool
import (
"bytes"
"sync"
)
// BytesBufferPool 定义 *bytes.Buffer 复用池的类型
type BytesBufferPool sync.Pool
func NewBytesBufferPool() *BytesBufferPool {
return &BytesBufferPool{New: func() any { return new(bytes.Buffer) }}
}
// Alloc 分配一个 *bytes.Buffer 对象
func (own *BytesBufferPool) Alloc() *bytes.Buffer {
return (*sync.Pool)(own).Get().(*bytes.Buffer)
}
// Dealloc 释放当前 *bytes.Buffer 对象
func (own *BytesBufferPool) Dealloc(obj *bytes.Buffer) {
obj.Reset()
(*sync.Pool)(own).Put(obj)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/leminewx/gokit.git
git@gitee.com:leminewx/gokit.git
leminewx
gokit
gokit
fe1b72bb8dfe

搜索帮助