sizedbufferpool

package
v0.10.8 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2026 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 GenericBufferPool

type GenericBufferPool interface {
	Get() *bytes.Buffer
	Put(*bytes.Buffer)
}

GenericBufferPool abstracts buffer pool implementations.

type SizedBufferPool

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

SizedBufferPool implements a pool of bytes.Buffers in the form of a bounded channel. Buffers are pre-allocated to the requested size.

func NewSizedBufferPool

func NewSizedBufferPool(size int, alloc int) (bp *SizedBufferPool)

NewSizedBufferPool creates a new BufferPool bounded to the given size. size defines the number of buffers to be retained in the pool and alloc sets the initial capacity of new buffers to minimize calls to make().

The value of alloc should seek to provide a buffer that is representative of most data written to the buffer (i.e. 95th percentile) without being overly large (which will increase static memory consumption). You may wish to track the capacity of your last N buffers (i.e. using an []int) prior to returning them to the pool as input into calculating a suitable alloc value.

func (*SizedBufferPool) Get

func (bp *SizedBufferPool) Get() (b *bytes.Buffer)

Get gets a Buffer from the SizedBufferPool, or creates a new one if none are available in the pool. Buffers have a pre-allocated capacity.

func (*SizedBufferPool) Put

func (bp *SizedBufferPool) Put(b *bytes.Buffer)

Put returns the given Buffer to the SizedBufferPool.

Jump to

Keyboard shortcuts

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