Documentation ¶
Overview ¶
Package freelist implements a thread-safe pool of objects of a defined size.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FreeList ¶
type FreeList[T any] struct { // contains filtered or unexported fields }
FreeList is a thread-safe pool of objects which one can borrow items from. It has the advantage over sync.Pool that the user can control how many objects are in the pool.
NOTE: Internally we use a channel as a buffer. This was found to have the best performance when contention was low, and reasonable performance when contention was high.
func NewFreeList ¶
NewFreeList creates a new free list.
func NewFreeListWithFactory ¶
NewFreeListWithFactory creates a new free list where the given function is used when creating new objects.
func (*FreeList[T]) Get ¶
Get borrows an object from the freelist. It will block until an object becomes available.
func (*FreeList[T]) Put ¶
Put adds v back to the freelist. It can also be used to setup the objects in the pool.