pool

package
v7.7.2 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2024 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type TieredBufferPool

type TieredBufferPool struct {
	// Min is Minimum the minimum buffer size.
	Min int

	// Max is the maximum buffer size. The pool will allocate buffers of that size,
	// But will not store them back.
	Max int
	// contains filtered or unexported fields
}

TieredBufferPool is a tiered pool for the buffers. It will store buffers in powers of two in sub pools. The size of buffers will ALWAYS be powers of two, and the pool will throw away buffers passed to it which do not conform to this rule.

func NewTieredBufferPool

func NewTieredBufferPool(min, max int) *TieredBufferPool

NewTieredBufferPool creates a new buffer pool. New buffers will be created with size and capacity of initBufferSize. If cap(buffer) is larger than maxBufferSize when it is put back in the buffer, it will be thrown away. This will prevent unwanted memory bloat and set a deterministic maximum-size for the pool which will not be exceeded.

func (*TieredBufferPool) Get

func (bp *TieredBufferPool) Get(sz int) []byte

Get returns a buffer from the pool. If sz is bigger than maxBufferSize, a fresh buffer will be created and not taken from the pool.

func (*TieredBufferPool) Put

func (bp *TieredBufferPool) Put(buf []byte)

Put will put the buffer back in the pool, unless cap(buf) is smaller than Min or larger than Max, or the size of the buffer is not a power of 2 in which case it will be thrown away.

Jump to

Keyboard shortcuts

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