pool

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BytesBufferPool = &bytesBufferPool{NewGeneric(1000, func(sz int) any {
	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) any) *Generic

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

func (*Generic) Get

func (p *Generic) Get(sz int) any

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 any)

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

type Resetter added in v0.4.0

type Resetter interface {
	Reset()
}

Resetter is an object that can be cleared for reuse.

type ResettingPool added in v0.4.0

type ResettingPool[T Resetter] struct {
	// contains filtered or unexported fields
}

ResettingPool is a typed sync.Pool that resets items on return. Unlike Generic, unused items may be garbage collected. A ResettingPool must not be copied after first use.

func NewResettingPool added in v0.4.0

func NewResettingPool[T Resetter](new func() T) *ResettingPool[T]

NewResettingPool returns a pool that creates items with new when empty. Use pointer types to avoid allocating when storing items in sync.Pool's interface values.

func (*ResettingPool[T]) Get added in v0.4.0

func (p *ResettingPool[T]) Get() T

Get returns an initialized item ready for use. Items returned to the pool have already been reset by Put.

func (*ResettingPool[T]) Put added in v0.4.0

func (p *ResettingPool[T]) Put(item T)

Put resets item before returning it to the pool, releasing references to payloads even if the item is not reused. The caller must no longer use item.

Jump to

Keyboard shortcuts

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