pool

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2025 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package pool provides a pool for reusing objects.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllRefsCount

func AllRefsCount() map[string]int

AllRefsCount returns the reference count of all pools.

func AllStacks added in v0.9.0

func AllStacks() map[string][]string

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

type Synced[T any] struct {
	sync.Pool
	// contains filtered or unexported fields
}

Synced is a pool that is safe for concurrent use.

func Register

func Register[T any](name string) *Synced[T]

Register registers a new pool with the given name.

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.

func (*Synced[T]) Put

func (p *Synced[T]) Put(v T)

Put puts an object back to the pool.

func (*Synced[T]) RefsCount

func (p *Synced[T]) RefsCount() int

RefsCount returns the reference count of the pool.

func (*Synced[T]) Stacks added in v0.9.0

func (p *Synced[T]) Stacks() []string

Stacks returns all recorded stack traces for objects in this pool.

type Trackable

type Trackable interface {
	// RefsCount returns the reference count of the pool.
	RefsCount() int
}

Trackable is the interface that wraps the RefsCount method.

Jump to

Keyboard shortcuts

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