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 ¶
- func Put(b *ByteBuffer)
- type ByteBuffer
- func (b *ByteBuffer) Bytes() []byte
- func (b *ByteBuffer) Cap() int
- func (b *ByteBuffer) Len() int
- func (b *ByteBuffer) ReadFrom(r io.Reader) (int64, error)
- func (b *ByteBuffer) Reset()
- func (b *ByteBuffer) Set(p []byte)
- func (b *ByteBuffer) SetString(s string)
- func (b *ByteBuffer) String() string
- func (b *ByteBuffer) Write(p []byte) (int, error)
- func (b *ByteBuffer) WriteByte(c byte) error
- func (b *ByteBuffer) WriteString(s string) (int, error)
- func (b *ByteBuffer) WriteTo(w io.Writer) (int64, error)
- type Pool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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 (*ByteBuffer) Bytes ¶
func (b *ByteBuffer) Bytes() []byte
Bytes returns the accumulated bytes (bytes.Buffer compatibility).
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.
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.