ringbuf

package
v1.45.0 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RingBuffer

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

RingBuffer is a thread-safe circular byte buffer that keeps the most recent data when capacity is exceeded. Used to buffer PTY output for replay on TUI reconnect.

The backing array is allocated once at construction and never reallocated: steady-state Write is zero-allocation. (The previous implementation append-reallocated and fully recompacted on every write once full — ~768 KB of memcpy per coalesced flush per busy pane.)

func NewRingBuffer

func NewRingBuffer(capacity int) *RingBuffer

NewRingBuffer creates a ring buffer with the given byte capacity.

func (*RingBuffer) Bytes

func (rb *RingBuffer) Bytes() []byte

Bytes returns a copy of all buffered data.

func (*RingBuffer) Gen added in v1.18.6

func (rb *RingBuffer) Gen() uint64

Gen returns the mutation generation, monotonically increasing across Write/Reset. Equal generations guarantee identical contents.

func (*RingBuffer) Len

func (rb *RingBuffer) Len() int

Len returns the current number of bytes in the buffer.

func (*RingBuffer) Reset

func (rb *RingBuffer) Reset()

Reset clears all buffered data (the backing array is retained).

func (*RingBuffer) Tail added in v1.18.6

func (rb *RingBuffer) Tail(n int) []byte

Tail returns a copy of the last n bytes (all bytes when n >= Len). Replaces the "Bytes() then keep 4 KB" pattern that copied the full buffer to read an excerpt.

func (*RingBuffer) Write

func (rb *RingBuffer) Write(p []byte)

Write appends p, trimming the oldest bytes when capacity is exceeded.

Jump to

Keyboard shortcuts

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