resourcepool

package
v0.0.0-...-303e327 Latest Latest
Warning

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

Go to latest
Published: May 22, 2023 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoSuitableSizeClass = errors.New("no suitable size class")

ErrNoSuitableSizeClass no suitable pool of size

View Source
var ErrPoolLimit = errors.New("resource pool limit")

ErrPoolLimit pool elements exceed its capacity

Functions

func SetReleaseInterval

func SetReleaseInterval(duration time.Duration)

SetReleaseInterval set release interval duration

func Zero

func Zero(b []byte)

Zero clean up the buffer b to zero bytes

Types

type MemPool

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

MemPool reused buffer pool

func NewMemPool

func NewMemPool(sizeClasses map[int]int) *MemPool

NewMemPool returns a MemPool within chan pool

func NewMemPoolWith

func NewMemPoolWith(sizeClasses map[int]int, newPool func(size, capacity int) Pool) *MemPool

NewMemPoolWith new MemPool with size-class and self-defined pool

func (*MemPool) Alloc

func (p *MemPool) Alloc(size int) ([]byte, error)

Alloc return a buffer, make a new if oversize

func (*MemPool) Get

func (p *MemPool) Get(size int) ([]byte, error)

Get return a suitable buffer

func (*MemPool) Put

func (p *MemPool) Put(b []byte) error

Put adds x to the pool, appropriately resize

func (*MemPool) Status

func (p *MemPool) Status() Status

Status returns status of memory pool

func (*MemPool) Zero

func (p *MemPool) Zero(b []byte)

Zero clean up the buffer b to zero bytes

type Pool

type Pool interface {
	// Get return nil and error if exceed pool's capacity
	Get() (interface{}, error)
	Put(x interface{})
	Cap() int
	Len() int
	// Idle return cached idle objects in pool.
	Idle() int
}

Pool resource pool support for sync.pool and capacity limit release resource if no used anymore no limit if capacity is negative

func NewChanPool

func NewChanPool(newFunc func() []byte, capacity int) Pool

NewChanPool return Pool with capacity, no limit if capacity is negative

func NewPool

func NewPool(newFunc func() interface{}, capacity int) Pool

NewPool return Pool with capacity, no limit if capacity is negative

type PoolStatus

type PoolStatus struct {
	Size     int `json:"size"`
	Capacity int `json:"capacity"`
	Running  int `json:"running"`
	Idle     int `json:"idle"`
}

PoolStatus status of the pool

type Status

type Status []PoolStatus

Status memory pools status

Jump to

Keyboard shortcuts

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