bytebufferpool

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2026 License: MIT Imports: 4 Imported by: 0 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

Overview

Package bytebufferpool provides a self-calibrating pool of byte buffers, bucketed by capacity, that reduces GC pressure on byte-heavy hot paths such as codec marshaling and broker payload encoding.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Put

func Put(b *ByteBuffer)

Put returns a byte buffer to the default pool.

Types

type ByteBuffer

type ByteBuffer struct {
	B []byte
}

ByteBuffer is a pooled byte buffer for append-like workloads. Obtain one with Get and return it with Put; its B must not be touched after Put.

func Get

func Get() *ByteBuffer

Get returns an empty byte buffer from the default pool.

func (*ByteBuffer) Bytes

func (b *ByteBuffer) Bytes() []byte

Bytes returns the accumulated bytes (bytes.Buffer compatibility).

func (*ByteBuffer) Cap

func (b *ByteBuffer) Cap() int

Cap returns the capacity of the buffer.

func (*ByteBuffer) Len

func (b *ByteBuffer) Len() int

Len returns the number of bytes in the buffer.

func (*ByteBuffer) ReadFrom

func (b *ByteBuffer) ReadFrom(r io.Reader) (int64, error)

ReadFrom implements io.ReaderFrom, appending all data read from r.

func (*ByteBuffer) Reset

func (b *ByteBuffer) Reset()

Reset empties the buffer without releasing capacity.

func (*ByteBuffer) Set

func (b *ByteBuffer) Set(p []byte)

Set replaces the buffer contents with p.

func (*ByteBuffer) SetString

func (b *ByteBuffer) SetString(s string)

SetString replaces the buffer contents with s.

func (*ByteBuffer) String

func (b *ByteBuffer) String() string

String returns the buffer contents as a string.

func (*ByteBuffer) Write

func (b *ByteBuffer) Write(p []byte) (int, error)

Write implements io.Writer, appending p.

func (*ByteBuffer) WriteByte

func (b *ByteBuffer) WriteByte(c byte) error

WriteByte appends a single byte.

func (*ByteBuffer) WriteString

func (b *ByteBuffer) WriteString(s string) (int, error)

WriteString appends s.

func (*ByteBuffer) WriteTo

func (b *ByteBuffer) WriteTo(w io.Writer) (int64, error)

WriteTo implements io.WriterTo.

type Pool

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

Pool is a byte-buffer pool. Distinct pools may be used for distinct buffer types to reduce memory waste.

func (*Pool) Get

func (p *Pool) Get() *ByteBuffer

Get returns a zero-length byte buffer. Return it with Put to reuse its underlying array and minimize GC overhead.

func (*Pool) Put

func (p *Pool) Put(b *ByteBuffer)

Put returns a byte buffer obtained via Get to the pool. b.B must not be touched after this call.

Jump to

Keyboard shortcuts

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