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, and a fast-access ring buffer to reduce main mutex contention.
type PoolShard ¶
type PoolShard[T any] struct { UnsafePoolShard // contains filtered or unexported fields }
PoolShard contains a reference to an original Pool, but with its own separate fast-access ring buffer to further reduce Pool's mutex contention.
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, and a fast-access ring buffer to reduce main mutex contention.
func NewUnsafePool ¶
func NewUnsafePool(check func(current, victim int) bool) UnsafePool
func (*UnsafePool) Shard ¶
func (p *UnsafePool) Shard() UnsafePoolShard
Shard returns a new UnsafePoolShard with a reference to this original pool. See type for more usage info.
type UnsafePoolShard ¶
type UnsafePoolShard struct {
// contains filtered or unexported fields
}
UnsafePoolShard contains a reference to an original UnsafePool, but with its own separate fast-access ring buffer to reduce the original UnsafePool's mutex contention.
func (*UnsafePoolShard) Get ¶
func (s *UnsafePoolShard) Get() unsafe.Pointer
func (*UnsafePoolShard) Original ¶
func (s *UnsafePoolShard) Original() *UnsafePool
Original returns a reference to the shard's origin pool.
func (*UnsafePoolShard) Put ¶
func (s *UnsafePoolShard) Put(ptr unsafe.Pointer)
func (*UnsafePoolShard) Release ¶
func (s *UnsafePoolShard) Release()
Release will release resources of this particular shard.
type UnsafeSimplePool ¶
type UnsafeSimplePool struct {
// Check determines how often to flush
// internal pools based on underlying
// current and victim pool sizes. It gets
// called on every pool Put() operation.
//
// A flush will start a new current
// pool, make victim the old current,
// and drop the existing victim pool.
Check 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 CheckGC().
Note it is NOT safe for concurrent use, you must protect it yourself!
func (*UnsafeSimplePool) GC ¶
func (p *UnsafeSimplePool) GC()
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