package pool
Import Path
github.com/gobwas/ws/internal/pool (on go.dev)
Dependency Relation
imports 3 packages, and imported by 2 packages
Involved Source Files
Package pool reuses objects that are distinguishable by size: byte slices,
bufio readers and writers and the like. Every power of two in a range has
its own sync.Pool, and a request is served from the class of the least
power of two not less than the requested size.
It is the part of github.com/gobwas/pool that ws uses, with generics
instead of interface{}.
Package-Level Type Names (only one)
Type Parameters:
T: any
Pool reuses objects of type T by size class.
Get returns a pooled object whose size class is the least power of two not
less than size, and that class size, to be passed to Put() later and to be
used as the allocation size when there is nothing to reuse.
The object is the zero value of T when the class is empty or when size is
out of the pool's range; the returned size is then size itself.
Put stores x for reuse under the size class of size. It drops x if size is
not one of the pool's classes.
func New[T](lo, hi int) *Pool[T]
Package-Level Functions (total 7)
GetBytes returns a pointer to a byte slice of length n, reused if possible.
The pointer, not the slice, is what the pool holds: a slice stored in a
sync.Pool is boxed into an interface, which allocates its header on every
Put. With a pointer the warm path does not allocate at all.
GetReader returns a bufio.Reader whose buffer has at least size bytes,
reused if possible. It reads from nothing until the caller calls Reset().
GetWriter returns a bufio.Writer whose buffer has at least size bytes,
reused if possible. It writes to nothing until the caller calls Reset().
Type Parameters:
T: any
New creates a Pool with a size class for every power of two in [lo, hi].
lo is rounded up to a power of two first; a lo of zero means one.
PutBytes stores bp for reuse by GetBytes(). Slices whose capacity is not a
power of two in the pool's range are dropped.
PutReader stores br for reuse by GetReader(). It resets br so that the
pooled reader does not keep its source alive.
PutWriter stores bw for reuse by GetWriter(). It resets bw so that the
pooled writer does not keep its destination alive.
![]() |
The pages are generated with Golds v0.8.7. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |