Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type GenericBufferPool ¶
GenericBufferPool abstracts buffer pool implementations.
type SizedBufferPool ¶
type SizedBufferPool struct {
// contains filtered or unexported fields
}
SizedBufferPool implements a pool of bytes.Buffers in the form of a bounded channel. Buffers are pre-allocated to the requested size.
func NewSizedBufferPool ¶
func NewSizedBufferPool(size int, alloc int) (bp *SizedBufferPool)
NewSizedBufferPool creates a new BufferPool bounded to the given size. size defines the number of buffers to be retained in the pool and alloc sets the initial capacity of new buffers to minimize calls to make().
The value of alloc should seek to provide a buffer that is representative of most data written to the buffer (i.e. 95th percentile) without being overly large (which will increase static memory consumption). You may wish to track the capacity of your last N buffers (i.e. using an []int) prior to returning them to the pool as input into calculating a suitable alloc value.
func (*SizedBufferPool) Get ¶
func (bp *SizedBufferPool) Get() (b *bytes.Buffer)
Get gets a Buffer from the SizedBufferPool, or creates a new one if none are available in the pool. Buffers have a pre-allocated capacity.
func (*SizedBufferPool) Put ¶
func (bp *SizedBufferPool) Put(b *bytes.Buffer)
Put returns the given Buffer to the SizedBufferPool.