Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Pool ¶
type Pool[T any] struct { UnsafePool // New is an optionally provided // allocator used when no value // is available for use in pool. New func() T // Reset is an optionally provided // value resetting function called // on passed value to Put(). Reset func(T) bool }
Pool provides a form of SimplePool with the addition of concurrency safety.
type SimplePool ¶
type SimplePool[T any] struct { UnsafeSimplePool // New is an optionally provided // allocator used when no value // is available for use in pool. New func() T // Reset is an optionally provided // value resetting function called // on passed value to Put(). Reset func(T) bool }
SimplePool provides a type-safe form of UnsafePool using generics.
Note it is NOT safe for concurrent use, you must protect it yourself!
func (*SimplePool[T]) Get ¶
func (p *SimplePool[T]) Get() T
func (*SimplePool[T]) Put ¶
func (p *SimplePool[T]) Put(t T)
type UnsafePool ¶
type UnsafePool struct {
// contains filtered or unexported fields
}
UnsafePool provides a form of UnsafeSimplePool with the addition of concurrency safety.
func NewUnsafePool ¶
func NewUnsafePool(gc func(current, victim int) bool) UnsafePool
type UnsafeSimplePool ¶
type UnsafeSimplePool struct { // GC determines how often to flush // internal pools based on underlying // current and victim pool sizes. // // A flush will start a new current // pool, make victim the old current, // and drop the existing victim pool. GC func(current, victim int) bool // contains filtered or unexported fields }
UnsafeSimplePool provides an incredibly simple memory pool implementation that stores ptrs to memory values, and regularly flushes internal pool structures according to GC function.
Note it is NOT safe for concurrent use, you must protect it yourself!
func (*UnsafeSimplePool) Clear ¶
func (p *UnsafeSimplePool) Clear()
func (*UnsafeSimplePool) Get ¶
func (p *UnsafeSimplePool) Get() unsafe.Pointer
func (*UnsafeSimplePool) Put ¶
func (p *UnsafeSimplePool) Put(ptr unsafe.Pointer)
func (*UnsafeSimplePool) Size ¶
func (p *UnsafeSimplePool) Size() int
Click to show internal directories.
Click to hide internal directories.