bpool: github.com/oxtoacart/bpool Index | Files

package bpool

import "github.com/oxtoacart/bpool"

Package bpool implements leaky pools of byte arrays and Buffers as bounded channels. It is based on the leaky buffer example from the Effective Go documentation: http://golang.org/doc/effective_go.html#leaky_buffer

Index

Package Files

bpool.go bufferpool.go bytepool.go sizedbufferpool.go

type BufferPool Uses

type BufferPool struct {
    // contains filtered or unexported fields
}

BufferPool implements a pool of bytes.Buffers in the form of a bounded channel.

func NewBufferPool Uses

func NewBufferPool(size int) (bp *BufferPool)

NewBufferPool creates a new BufferPool bounded to the given size.

func (*BufferPool) Get Uses

func (bp *BufferPool) Get() (b *bytes.Buffer)

Get gets a Buffer from the BufferPool, or creates a new one if none are available in the pool.

func (*BufferPool) Put Uses

func (bp *BufferPool) Put(b *bytes.Buffer)

Put returns the given Buffer to the BufferPool.

type BytePool Uses

type BytePool struct {
    // contains filtered or unexported fields
}

BytePool implements a leaky pool of []byte in the form of a bounded channel.

func NewBytePool Uses

func NewBytePool(maxSize int, width int) (bp *BytePool)

NewBytePool creates a new BytePool bounded to the given maxSize, with new byte arrays sized based on width.

func (*BytePool) Get Uses

func (bp *BytePool) Get() (b []byte)

Get gets a []byte from the BytePool, or creates a new one if none are available in the pool.

func (*BytePool) Put Uses

func (bp *BytePool) Put(b []byte)

Put returns the given Buffer to the BytePool.

func (*BytePool) Width Uses

func (bp *BytePool) Width() (n int)

Width returns the width of the byte arrays in this pool.

type SizedBufferPool Uses

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 Uses

func NewSizedBufferPool(size int, alloc int) (bp *SizedBufferPool)

SizedBufferPool 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 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 Uses

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 Uses

func (bp *SizedBufferPool) Put(b *bytes.Buffer)

Put returns the given Buffer to the SizedBufferPool.

Package bpool imports 1 packages (graph) and is imported by 47 packages. Updated 2017-06-07. Refresh now. Tools for package owners.