Documentation ¶
Overview ¶
Package pool provides an object pool that trades off the cost of creation versus retention. It is meant to avoid the pessimal behaviour (see issue 23199) seen when using a regular sync.Pool with objects of dynamic sizes; objects that are too large are kept alive by repeat usages that don't need such sizes.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Dynamic ¶
type Dynamic struct { Pool interface { Get() interface{} Put(interface{}) } // The utility below which the cost of creating the object is more expensive // than just keeping it. Set this to the expected object size (or perhaps a // bit larger to reduce allocations more). MinUtility float64 // contains filtered or unexported fields }
A Dynamic pool is like a sync.Pool for objects of varying sizes.
It prevents the indefinite retention of (too) large objects by keeping a history of required object sizes (utility) and comparing them to the actual object size (cost) before accepting an object.
Click to show internal directories.
Click to hide internal directories.