last updated: Oct 20, 2023

zeropool is a zero-allocation type-safe sync.Pool

// The function provided to zeropool.New() makes a Pool of a correct type using generics.
pool := zeropool.New(func() []byte { return nil })

// This is a []byte, no need to make type-assertion, no need to de-reference.
buf := pool.Get()

// This does not allocate.

Go provides sync.Pool pool implementation that allows storing any values (interface{} values). It is great but has two major drawbacks:

↑ up