pbytes

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2019 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package pbytes contains tools for pooling byte pool. Note that by default it reuse slices with capacity from 128 to 65536 bytes.

Index

Constants

This section is empty.

Variables

View Source
var DefaultPool = New(128, 65536)

DefaultPool is used by pacakge level functions.

Functions

func Get

func Get(n, c int) []byte

Get returns probably reused slice of bytes with at least capacity of c and exactly len of n. Get is a wrapper around DefaultPool.Get().

func GetCap

func GetCap(c int) []byte

GetCap returns probably reused slice of bytes with at least capacity of n. GetCap is a wrapper around DefaultPool.GetCap().

func GetLen

func GetLen(n int) []byte

GetLen returns probably reused slice of bytes with at least capacity of n and exactly len of n. GetLen is a wrapper around DefaultPool.GetLen().

func Put

func Put(p []byte)

Put returns given slice to reuse pool. Put is a wrapper around DefaultPool.Put().

Types

type Pool

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

Pool contains logic of reusing byte slices of various size.

func Custom

func Custom(opts ...pool.Option) *Pool

New creates new Pool with given options.

func New

func New(min, max int) *Pool

New creates new Pool that reuses slices which size is in logarithmic range [min, max].

Note that it is a shortcut for Custom() constructor with Options provided by pool.WithLogSizeMapping() and pool.WithLogSizeRange(min, max) calls.

func (*Pool) Get

func (p *Pool) Get(n, c int) []byte

Get returns probably reused slice of bytes with at least capacity of c and exactly len of n.

func (*Pool) GetCap

func (p *Pool) GetCap(c int) []byte

GetCap returns probably reused slice of bytes with at least capacity of n.

func (*Pool) GetLen

func (p *Pool) GetLen(n int) []byte

GetLen returns probably reused slice of bytes with at least capacity of n and exactly len of n.

func (*Pool) Put

func (p *Pool) Put(bts []byte)

Put returns given slice to reuse pool. It does not reuse bytes whose size is not power of two or is out of pool min/max range.

Jump to

Keyboard shortcuts

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