pool

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2025 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BytesBufferPool = NewGeneric(1000, func(sz int) interface{} {
	return &gbp.Buffer{Pool: gbp.GlobalPool}
})

Functions

This section is empty.

Types

type Generic

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

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

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 an 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.

Jump to

Keyboard shortcuts

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