Documentation ¶
Overview ¶
Package bytes implements functions for manipulating byte slices.
Index ¶
- type BufferPool
- func (bp *BufferPool) Add(buf *bytes.Buffer)
- func (bp *BufferPool) AddWait(buf *bytes.Buffer)
- func (bp *BufferPool) Cap() int
- func (bp *BufferPool) Clear()
- func (bp *BufferPool) Fill()
- func (bp *BufferPool) Get() (buf *bytes.Buffer)
- func (bp *BufferPool) GetWait() *bytes.Buffer
- func (bp *BufferPool) Len() int
- type Pool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BufferPool ¶
type BufferPool struct {
// contains filtered or unexported fields
}
BufferPool is a pool implementation of bytes.Buffer. This allows to reuse buffers, which means less allocations. Buffers are guaranteed to live in memory, which is a key difference between sync.Pool.
func NewBufferPool ¶
func NewBufferPool(n, max int) BufferPool
NewBufferPool creates a pool that will hold up to n buffers. Any new buffer will be created with up to max bytes.
func (*BufferPool) Add ¶
func (bp *BufferPool) Add(buf *bytes.Buffer)
Add appends buf to the pool. Add behaves like AddWait, but if there is no more room for buffers, buf will be discarded.
func (*BufferPool) AddWait ¶ added in v0.7.0
func (bp *BufferPool) AddWait(buf *bytes.Buffer)
AddWait appends buf to the pool. If there is no room for more buffers, AddWait will wait until buf can be appended. If buf is nil or has more than bp.max bytes, it will be discarded and a new buffer will be allocated. After calling AddWait, buf must not be used anymore.
func (*BufferPool) Clear ¶
func (bp *BufferPool) Clear()
Clear discards all the buffers in the pool.
func (*BufferPool) Fill ¶
func (bp *BufferPool) Fill()
Fill fills the pool up to its available capacity.
func (*BufferPool) Get ¶
func (bp *BufferPool) Get() (buf *bytes.Buffer)
Get returns a buffer from the pool. If there are no buffers in the pool, a new one with bp.max bytes will be returned.
func (*BufferPool) GetWait ¶ added in v0.7.0
func (bp *BufferPool) GetWait() *bytes.Buffer
GetWait returns a buffer from the pool. If there are no buffers in the pool, this will wait until one is available.
func (*BufferPool) Len ¶
func (bp *BufferPool) Len() int
Len returns the amount of buffers in the pool.
type Pool ¶ added in v0.7.0
type Pool struct {
// contains filtered or unexported fields
}
Pool is a pool implementation of byte slices. This allows to reuse slices, which means less allocations. Slices are guaranteed to live in memory, which is a key difference between sync.Pool.
func NewPool ¶ added in v0.7.0
NewPool creates a pool that will hold up to n slices. Any new slice will be created with up to max bytes.
func (*Pool) Add ¶ added in v0.7.0
Add appends s to the pool. Add behaves like AddWait, but if there is no more room for slices, s will be discarded.
func (*Pool) AddWait ¶ added in v0.7.0
AddWait appends s to the pool. If there is no room for more slices, AddWait will wait until s can be appended. If s is nil or has more than p.max bytes, it will be discarded and a new slice will be allocated. After calling AddWait, s must not be used anymore.
func (*Pool) Clear ¶ added in v0.7.0
func (p *Pool) Clear()
Clear discards all the slices in the pool.
func (*Pool) Fill ¶ added in v0.7.0
func (p *Pool) Fill()
Fill fills the pool up to its available capacity.
func (*Pool) Get ¶ added in v0.7.0
Get returns a slice from the pool. If there are no slices in the pool, a new one with a capacity of p.max bytes will be returned.