1
0
buffer/pool.go

37 lines
484 B
Go

package buffer
import "sync"
type noPool struct {
allocSize int
}
type pool struct {
sp *sync.Pool
}
func newPool(allocSize int) *pool {
sp := &sync.Pool{
New: func() any {
return make([]byte, allocSize)
},
}
return &pool{sp: sp}
}
func (p noPool) Get() ([]byte, error) {
return make([]byte, p.allocSize), nil
}
func (noPool) Put([]byte) {
}
func (p *pool) Get() ([]byte, error) {
return p.sp.Get().([]byte), nil
}
func (p *pool) Put(b []byte) {
p.sp.Put(b)
}