Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrPoolExhausted = errors.New("pool exhausted")
ErrPoolExhausted is returned if a pool cannot provide the request bytes.
Functions ¶
This section is empty.
Types ¶
type BucketedBytes ¶ added in v0.19.0
type BucketedBytes struct {
// contains filtered or unexported fields
}
BucketedBytes is a bucketed pool for variably sized byte slices. It can be configured to not allow more than a maximum number of bytes being used at a given time. Every byte slice obtained from the pool must be returned.
func MustNewBucketedBytes ¶ added in v0.32.0
func MustNewBucketedBytes(minSize, maxSize int, factor float64, maxTotal uint64) *BucketedBytes
MustNewBucketedBytes is like NewBucketedBytes but panics if construction fails. Useful for package internal pools.
func NewBucketedBytes ¶ added in v0.19.0
func NewBucketedBytes(minSize, maxSize int, factor float64, maxTotal uint64) (*BucketedBytes, error)
NewBucketedBytes returns a new Bytes with size buckets for minSize to maxSize increasing by the given factor and maximum number of used bytes. No more than maxTotal bytes can be used at any given time unless maxTotal is set to 0.
func (*BucketedBytes) Get ¶ added in v0.19.0
func (p *BucketedBytes) Get(sz int) (*[]byte, error)
Get returns a new byte slice that fits the given size.
func (*BucketedBytes) Put ¶ added in v0.19.0
func (p *BucketedBytes) Put(b *[]byte)
Put returns a byte slice to the right bucket in the pool.
func (*BucketedBytes) UsedBytes ¶ added in v0.35.0
func (p *BucketedBytes) UsedBytes() uint64
type Bytes ¶ added in v0.19.0
type Bytes interface { // Get returns a new byte slices that fits the given size. Get(sz int) (*[]byte, error) // Put returns a byte slice to the right bucket in the pool. Put(b *[]byte) }
Bytes is a pool of bytes that can be reused.
type NoopBytes ¶ added in v0.19.0
type NoopBytes struct{}
NoopBytes is pool that always allocated required slice on heap and ignore puts.
type Work ¶ added in v0.35.0
type Work func()
Work is a unit of item to be worked on, like Java Runnable.
type WorkerPool ¶ added in v0.35.0
type WorkerPool interface { // Init initializes the worker pool. Init() // Go waits until the next worker becomes available and executes the given work. Go(work Work) // Close cancels all workers and waits for them to finish. Close() // Size returns the number of workers in the pool. Size() int }
WorkerPool is a pool of goroutines that are reusable, similar to Java ThreadPool.
func NewWorkerPool ¶ added in v0.35.0
func NewWorkerPool(workers uint) WorkerPool