pool

package
v0.0.0-...-5d73d95 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 24, 2024 License: AGPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BucketedPool

type BucketedPool[T ~[]E, E any] struct {
	// contains filtered or unexported fields
}

BucketedPool is a bucketed pool for variably sized slices. It is similar to prometheus/prometheus' pool.Pool, but: - uses zeropool.Pool internally - uses generics to avoid reflection - only supports using a factor of 2

func NewBucketedPool

func NewBucketedPool[T ~[]E, E any](maxSize uint, makeFunc func(int) T) *BucketedPool[T, E]

NewBucketedPool returns a new BucketedPool with buckets separated by a factor of 2 up to maxSize.

func (*BucketedPool[T, E]) Get

func (p *BucketedPool[T, E]) Get(size int) T

Get returns a new slice with capacity greater than or equal to size. If no bucket large enough exists, a slice larger than the requested size of the next power of two is returned. Get guarantees the resulting slice always has a capacity in power of twos.

func (*BucketedPool[T, E]) Put

func (p *BucketedPool[T, E]) Put(s T)

Put adds a slice to the right bucket in the pool. If the slice does not belong to any bucket in the pool, it is ignored.

type FastReleasingSlabPool

type FastReleasingSlabPool[T any] struct {
	// contains filtered or unexported fields
}

FastReleasingSlabPool is similar to SlabPool, but allows for fast release of slabs if they are not used anymore.

func NewFastReleasingSlabPool

func NewFastReleasingSlabPool[T any](delegate Interface, slabSize int) *FastReleasingSlabPool[T]

NewFastReleasingSlabPool returns a new "fast-releasing" slab pool.

func (*FastReleasingSlabPool[T]) Get

func (b *FastReleasingSlabPool[T]) Get(size int) ([]T, int)

Get returns a slice of T with the given length and capacity (both match), and slab ID that needs be used in Release call.

func (*FastReleasingSlabPool[T]) Release

func (b *FastReleasingSlabPool[T]) Release(slabID int)

Release decreases reference counter for given slab ID. (Slab ids equal to or less than 0 are ignored). If reference counter is 0, slab may be returned to the delegate pool.

type Interface

type Interface interface {
	// Put is sync.Pool.Put().
	Put(x any)
	// Get is sync.Pool.Get().
	Get() any
}

Interface defines the same functions of sync.Pool.

type NoopPool

type NoopPool struct{}

func (NoopPool) Get

func (NoopPool) Get() any

func (NoopPool) Put

func (NoopPool) Put(any)

type SafeSlabPool

type SafeSlabPool[T any] struct {
	// contains filtered or unexported fields
}

SafeSlabPool wraps SlabPool to make it safe for concurrent use from multiple goroutines

func NewSafeSlabPool

func NewSafeSlabPool[T any](delegate Interface, slabSize int) *SafeSlabPool[T]

func (*SafeSlabPool[T]) Get

func (b *SafeSlabPool[T]) Get(size int) []T

func (*SafeSlabPool[T]) Release

func (b *SafeSlabPool[T]) Release()

type SafeSlabPoolAllocator

type SafeSlabPoolAllocator struct {
	// contains filtered or unexported fields
}

func NewSafeSlabPoolAllocator

func NewSafeSlabPoolAllocator(pool *SafeSlabPool[byte]) *SafeSlabPoolAllocator

NewSafeSlabPoolAllocator wraps the input SafeSlabPool[byte] into an allocator suitable to be used with a cache client. This function returns nil if the input SafeSlabPool[byte] is nil.

func (*SafeSlabPoolAllocator) Get

func (a *SafeSlabPoolAllocator) Get(sz int) *[]byte

func (*SafeSlabPoolAllocator) Put

func (a *SafeSlabPoolAllocator) Put(_ *[]byte)

type SlabPool

type SlabPool[T any] struct {
	// contains filtered or unexported fields
}

SlabPool wraps Interface and adds support to get a sub-slice of the data type T from the pool, trying to fit the slices picked from the pool as much as possible.

The slices returned by SlabPool.Get() will be released back to the pool once SlabPool.Release() is called.

SlabPool is NOT concurrency safe.

func NewSlabPool

func NewSlabPool[T any](delegate Interface, slabSize int) *SlabPool[T]

func (*SlabPool[T]) Get

func (b *SlabPool[T]) Get(size int) []T

Get returns a slice of T with the given length and capacity (both matches).

func (*SlabPool[T]) Release

func (b *SlabPool[T]) Release()

Release all slices returned by Get. It's unsafe to access slices previously returned by Get after calling Release().

type TrackedPool

type TrackedPool struct {
	Parent  Interface
	Balance atomic.Int64
	Gets    atomic.Int64
}

func (*TrackedPool) Get

func (p *TrackedPool) Get() any

func (*TrackedPool) Put

func (p *TrackedPool) Put(x any)

func (*TrackedPool) Reset

func (p *TrackedPool) Reset()

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL