multibuf

package
v0.0.0-rc8 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type PooledMultiBuffer

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

PooledMultiBuffer provides io.Reader interface over multiple bytes.Buffers (like io.MultiReader) buffers are taken from sync.Pool to reduce GC pressure

func NewPooledMultiBuffer

func NewPooledMultiBuffer(count int, pool *sync.Pool) *PooledMultiBuffer

NewPooledMultiBuffer makes new PooledMiltiBuffer. Pool is used to manage memory for buffers and reuse them between multiple PooledMultiBuffers Count is used as a hint to possible buffer count. You may provide 0 as initial count.

func (*PooledMultiBuffer) AcquireBuffer

func (q *PooledMultiBuffer) AcquireBuffer(initialCap int) *bytes.Buffer

AcquireBuffer provides a buffer. It may allocate new buffer in memory or take it from internal memory pool. To optimize memory allocations you can set initial buffer capacity if it is known. It is guaranteed that internal buffers read order is the same as the order of AcquireBuffer calls

func (*PooledMultiBuffer) Close

func (q *PooledMultiBuffer) Close()

Close release all acquired buffers and return them into memory pool Read should not be called after close

func (*PooledMultiBuffer) Read

func (q *PooledMultiBuffer) Read(p []byte) (int, error)

Read implements io.Reader interface It is guaranteed that internal buffers read order is the same as the order of AcquireBuffer calls

Jump to

Keyboard shortcuts

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