bpool

package
v0.7.0-rc1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 12, 2016 License: Apache-2.0, Apache-2.0 Imports: 1 Imported by: 0

README

bpool GoDoc

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

Install

go get github.com/oxtoacart/bpool

Documentation

See godoc.org or use godoc github.com/oxtoacart/bpool

Example


var bufpool *bpol.BufferPool

func main() {

    bufpool = bpool.NewBufferPool(48)

}

func someFunction() error {

     // Get a buffer from the pool
     buf := bufpool.Get()
     ...
     ...
     ...
     // Return the buffer to the pool
     bufpool.Put(buf)
     
     return nil
}

Documentation

Overview

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

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 implements a pool of bytes.Buffers in the form of a bounded channel.

func NewBufferPool

func NewBufferPool(size int) (bp *BufferPool)

NewBufferPool creates a new BufferPool bounded to the given size.

func (*BufferPool) Get

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

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

Put returns the given Buffer to the BufferPool.

type BytePool

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

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

func NewBytePool

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

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

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

Put returns the given Buffer to the BytePool.

func (*BytePool) Width

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

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL