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 {
MinAlloc, BucketCount int
// contains filtered or unexported fields
}
Pool maintains 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.
The zero-value Pool is ready to use, defaulting to BucketCount=20 and MinAlloc=1024 (max size = ~1MiB). Most applications will not benefit from tuning these parameters.
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.
var Default Pool
A default global pool.