bytespool

package
v0.62.6 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2025 License: Apache-2.0 Imports: 7 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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