Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var 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 ¶
NewGeneric returns a Generic pool with capacity for max items to be pool.
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.