zeropool

package
v0.49.0 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2024 License: Apache-2.0 Imports: 1 Imported by: 7

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Pool

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

Pool is a type-safe pool of items that does not allocate pointers to items. That is not entirely true, it does allocate sometimes, but not most of the time, just like the usual sync.Pool pools items most of the time, except when they're evicted. It does that by storing the allocated pointers in a secondary pool instead of letting them go, so they can be used later to store the items again.

Zero value of Pool[T] is valid, and it will return zero values of T if nothing is pooled.

func New

func New[T any](item func() T) Pool[T]

New creates a new Pool[T] with the given function to create new items. A Pool must not be copied after first use.

func (*Pool[T]) Get

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

Get returns an item from the pool, creating a new one if necessary. Get may be called concurrently from multiple goroutines.

func (*Pool[T]) Put

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

Put adds an item to the pool.

Jump to

Keyboard shortcuts

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