Documentation
¶
Overview ¶
Package bufferpool supports object pooling for byte buffers.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Pool ¶
type Pool struct {
// contains filtered or unexported fields
}
Pool maintains a list of buffers, exponentially increasing in size. Values MUST be initialized by NewPool().
Buffer instances are safe for concurrent access.
A default global pool.
This pool defaults to bucketCount=20 and minAlloc=1024 (max size = ~1MiB).
func NewPool ¶
NewPool creates a list of BucketCount buckets that contain buffers of exponentially-increasing capacity, 1 << 0 to 1 << BucketCount.
The minAlloc field specifies the minimum capacity of new buffers allocated by Pool, which improves reuse of small buffers. For the avoidance of doubt: calls to Get() with size < minAlloc return a buffer of len(buf) = size and cap(buf) >= minAlloc. MinAlloc MUST NOT exceed 1 << BucketCount, or method calls to Pool will panic.
Passing zero to the parameters will default bucketCount to 20 and minAlloc to 1024 (max size = ~1MiB).
As a general rule, increasing MinAlloc reduces GC latency at the expense of increased memory usage. Increasing BucketCount can reduce GC latency in applications that frequently allocate large buffers.