pool - ActiveState ActiveGo 1.8
...

Package pool

import "github.com/influxdata/influxdb/pkg/pool"
Overview
Index

Overview ▾

Package pool provides pool structures to help reduce garbage collector pressure.

type Bytes

Bytes is a pool of byte slices that can be re-used. Slices in this pool will not be garbage collected when not in use.

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

func NewBytes

func NewBytes(max int) *Bytes

NewBytes returns a Bytes pool with capacity for max byte slices to be pool.

func (*Bytes) Get

func (p *Bytes) Get(sz int) []byte

Get returns a byte slice size with at least sz capacity. Items returned may not be in the zero state and should be reset by the caller.

func (*Bytes) Put

func (p *Bytes) Put(c []byte)

Put returns a slice back to the pool. If the pool is full, the byte slice is discarded.

type Generic

Generic is a pool of types that can be re-used. Items in this pool will not be garbage collected when not in use.

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

func NewGeneric

func NewGeneric(max int, fn func(sz int) interface{}) *Generic

NewGeneric returns a Generic pool with capacity for max items to be pool.

func (*Generic) Get

func (p *Generic) Get(sz int) interface{}

Get returns a item from the pool or a new instance if the pool is empty. Items returned may not be in the zero state and should be reset by the caller.

func (*Generic) Put

func (p *Generic) Put(c interface{})

Put returns an item back to the pool. If the pool is full, the item is discarded.