Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( SyncBased = SPI(0) MpoolBased = SPI(1) )
Functions ¶
func CreatePool ¶
func CreatePool[T ReusableObject]( new func() *T, reset func(*T), opts *Options[T])
CreatePool create pool instance.
func RunReuseTests ¶
func RunReuseTests(fn func())
Types ¶
type Options ¶
type Options[T ReusableObject] struct { // contains filtered or unexported fields }
Options options to create object pool
func DefaultOptions ¶
func DefaultOptions[T ReusableObject]() *Options[T]
DefaultOptions default options
func (*Options[T]) WithEnableChecker ¶
WithEnableChecker enable check double free, leak free.
func (*Options[T]) WithReleaseFunc ¶
WithReleaseFunc with specified release function. The release function is used to release resources before gc.
type Pool ¶
type Pool[T ReusableObject] interface { Alloc() *T Free(*T) }
Pool is a pool of temporary objects, designed to reduce the creation of temporary objects to reduce GC pressure.
There are many places throughout the system where temporary objects need to be created, and if these places are in our hot path, we need to consider using a pool to reduce the number of temporary objects.
type ReusableObject ¶
type ReusableObject interface { // TypeName returns the name of the object type. We cannot use reflect.TypeOf to get // the name of the object type, to avoid mem allocate. // Outdated, may delete later. TypeName() string }
ReusableObject all reusable objects must implements this interface
Click to show internal directories.
Click to hide internal directories.