pools

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2020 License: BSD-3-Clause Imports: 3 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Bytes = New(32, 64*(1<<10))
View Source
var TinyBytes = New(4, 128)

Functions

func AcquireTimer

func AcquireTimer(timeout time.Duration) *time.Timer

func AcquireWaitGroup

func AcquireWaitGroup() *sync.WaitGroup

func Go added in v0.1.1

func Go(f func())

func ReleaseTimer

func ReleaseTimer(t *time.Timer)

func ReleaseWaitGroup

func ReleaseWaitGroup(wg *sync.WaitGroup)

func ResetTimer

func ResetTimer(t *time.Timer, period time.Duration)

Types

type Pool

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

Pool contains logic of reusing objects distinguishable by size in generic way.

func New

func New(min, max int) *Pool

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

Note that it is a shortcut for Custom() constructor with Options provided by WithLogSizeMapping() and 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