bytespool

package
v0.64.1 Latest Latest
Warning

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

Go to latest
Published: Dec 25, 2025 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FlushReleaseWriter

func FlushReleaseWriter(w *Writer) error

func Release

func Release(buf *Buffer)

Release puts the byte buffer to the global pool.

func ReleaseWriter added in v0.62.0

func ReleaseWriter(w *Writer)

Types

type Buffer

type Buffer struct {
	B []byte
}

func Acquire

func Acquire(capacity int) *Buffer

Acquire gets a byte buffer with zero length from the global pool.

func AcquireLen

func AcquireLen(length int) *Buffer

AcquireLen gets a byte buffer with given length from the global pool.

func (*Buffer) Reset

func (b *Buffer) Reset()

func (*Buffer) Write

func (b *Buffer) Write(buf []byte) (int, error)

type Pool

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

Pool consists of N sync.Pool's, each pool is a set of temporary Buffer with at least 2^n+8 capacity where the n is the pool index.

func New

func New() *Pool

func (*Pool) Acquire

func (p *Pool) Acquire(capacity int) *Buffer

Acquire retrieves a Buffer with given length and rounded up capacity of the power of two.

func (*Pool) Release

func (p *Pool) Release(buf *Buffer)

Release returns Buffer to the pool.

type Writer

type Writer struct {
	Buf *Buffer
	// contains filtered or unexported fields
}

Writer is a buffered writer that can use a provided byte slice, unlike bufio.Writer. This can be useful directly appending to an existing byte slice (for example strconv.AppendUint).

func AcquireWriterSize

func AcquireWriterSize(out io.Writer, size int) *Writer

func (*Writer) Flush

func (w *Writer) Flush() error

func (*Writer) Write

func (w *Writer) Write(b []byte) (int, error)

func (*Writer) WriteString

func (w *Writer) WriteString(s string) (int, error)

Jump to

Keyboard shortcuts

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