pool

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: May 25, 2022 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package pool provides an object pool that trades off the cost of creation versus retention. It is meant to avoid the pessimal behaviour (see issue 23199) seen when using a regular sync.Pool with objects of dynamic sizes; objects that are too large are kept alive by repeat usages that don't need such sizes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Dynamic

type Dynamic struct {
	Pool interface {
		Get() interface{}
		Put(interface{})
	}

	// The utility below which the cost of creating the object is more expensive
	// than just keeping it. Set this to the expected object size (or perhaps a
	// bit larger to reduce allocations more).
	MinUtility float64
	// contains filtered or unexported fields
}

A Dynamic pool is like a sync.Pool for objects of varying sizes.

It prevents the indefinite retention of (too) large objects by keeping a history of required object sizes (utility) and comparing them to the actual object size (cost) before accepting an object.

func (*Dynamic) Get

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

func (*Dynamic) Put

func (p *Dynamic) Put(v interface{}, utility, cost float64) bool

Put is like sync.Pool.Put, with a few differences. The utility is a measure of what part of the object was actually used. The cost is a measure of the total "size" of the object. Utility must be smaller than or equal to cost.

Jump to

Keyboard shortcuts

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