localpool

package
v1.1.0-beta.0...-9a1b696 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2023 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LocalPool

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

LocalPool is an thread local object pool. It's similar to sync.Pool but has some difference - It can define the size of the pool. - It never get GCed.

func NewLocalPool

func NewLocalPool(sizePerProc int, newFn func() interface{}, resetFn func(obj interface{})) *LocalPool

NewLocalPool creates a pool. The sizePerProc is pool size for each PROC, so total pool size is (GOMAXPROCS * sizePerProc) It can only be used when the GOMAXPROCS never change after the pool created. newFn is the function to create a new object. resetFn is the function called before put back to the pool, it can be nil.

func (*LocalPool) Get

func (p *LocalPool) Get() interface{}

Get gets an object from the pool.

func (*LocalPool) Put

func (p *LocalPool) Put(obj interface{}) bool

Put puts an object back to the pool. It returns true if the pool is not full and the obj is successfully put into the pool.

Jump to

Keyboard shortcuts

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