genpool

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2026 License: Unlicense Imports: 1 Imported by: 1

README

genpool

Simple generic wrapper around sync.Pool.

Basic pool

var gPool = genpool.New[bytes.Buffer]()

Pool with function

var gPool = genpool.NewFunc[Ctx](func() *Ctx {
	return &Ctx{
		// ...
	}
})

Using the pool

func something() {
	buffer := gPool.Get()
	defer gPool.Put(buffer)
	// do something with buffer
}

License

This is free and unencumbered software released into the public domain.

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
}

func New

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

func NewFunc

func NewFunc[T any](new func() *T) Pool[T]

func (*Pool[T]) Get

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

func (*Pool[T]) Put

func (gp *Pool[T]) Put(x *T)

type Resetter

type Resetter interface {
	Reset()
}

Jump to

Keyboard shortcuts

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