Documentation
¶
Overview ¶
Package pool provides a pool for reusing objects.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AllRefsCount ¶
AllRefsCount returns the reference count of all pools.
func AllStacks ¶ added in v0.9.0
AllStacks returns all recorded stack traces for leaked objects from all pools.
func EnableStackTracking ¶ added in v0.9.0
func EnableStackTracking(enabled bool)
EnableStackTracking enables or disables stack tracking for all pools.
Types ¶
type Bounded ¶ added in v0.11.0
type Bounded[T comparable] struct { // contains filtered or unexported fields }
Bounded is a deterministic pool whose retained objects cannot exceed a configured aggregate size.
func RegisterBounded ¶ added in v0.11.0
func RegisterBounded[T comparable](name string, maxSize int64, newValue func() T, sizeOf func(T) int64) *Bounded[T]
RegisterBounded registers an aggregate-size-bounded pool with the given name.
func (*Bounded[T]) Discard ¶ added in v0.11.0
func (p *Bounded[T]) Discard(value T)
Discard releases an object without retaining it for reuse.
func (*Bounded[T]) Get ¶ added in v0.11.0
func (p *Bounded[T]) Get() T
Get obtains an object from the pool or creates one when the pool is empty.
func (*Bounded[T]) Put ¶ added in v0.11.0
Put releases an object and retains it when the aggregate size limit permits reuse.
func (*Bounded[T]) RefsCount ¶ added in v0.11.0
RefsCount returns the number of objects currently checked out from the pool.
func (*Bounded[T]) RetainedSize ¶ added in v0.11.0
RetainedSize returns the aggregate size of objects currently retained by the pool.
type StackTracker ¶ added in v0.9.0
type StackTracker interface {
// Stacks returns all recorded stack traces for objects in the pool.
Stacks() []string
}
StackTracker is the interface that wraps the Stacks method.
type Synced ¶
Synced is a pool that is safe for concurrent use.
func (*Synced[T]) Discard ¶ added in v0.11.0
func (p *Synced[T]) Discard(v T)
Discard releases a checked-out object without returning it to the pool.
func (*Synced[T]) Get ¶
func (p *Synced[T]) Get() T
Get returns an object from the pool. If the pool is empty, nil is returned.
type Trackable ¶
type Trackable interface {
// RefsCount returns the reference count of the pool.
RefsCount() int
}
Trackable is the interface that wraps the RefsCount method.
type Tracker ¶ added in v0.10.0
type Tracker struct {
// contains filtered or unexported fields
}
Tracker tracks object lifecycle (Acquire/Release) without pooling. It integrates with AllRefsCount/AllStacks to help detect leaked resources.
func RegisterTracker ¶ added in v0.10.0
RegisterTracker registers a new lifecycle tracker with the given name.
func (*Tracker) RefsCount ¶ added in v0.10.0
RefsCount returns the reference count of tracked objects.