infra
/
goutils
Archived
1
0
Fork 0
This repository has been archived on 2022-04-06. You can view files and clone it, but cannot push or open issues or pull requests.
goutils/buf/bytebuf_pool.go

29 lines
385 B
Go

package buf
import (
"sync"
)
const (
defaultByteBufferSize = 4096
)
type ByteBufferPool struct {
pool sync.Pool
}
func (p *ByteBufferPool) Acquire() *ByteBuffer {
v := p.pool.Get()
if v == nil {
return &ByteBuffer{
B: make([]byte, 0, defaultByteBufferSize),
}
}
return v.(*ByteBuffer)
}
func (p *ByteBufferPool) Release(b *ByteBuffer) {
b.Reset()
p.pool.Put(b)
}