ringbuffer

package
v0.2.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrQueueFull   = errors.New("queue is full")
	ErrInvalidSize = errors.New("size must be power of two")
	ErrClosed      = errors.New("ring buffer closed")
)

Functions

This section is empty.

Types

type RingBuffer

type RingBuffer[T any] struct {
	// contains filtered or unexported fields
}

RingBuffer represents the MPMC ring buffer

func New

func New[T any](size uint32) (*RingBuffer[T], error)

New creates a new MPMC ring buffer

func (*RingBuffer[T]) Close

func (rb *RingBuffer[T]) Close()

Close closes the ring buffer

func (*RingBuffer[T]) Read

func (rb *RingBuffer[T]) Read() (T, error)

Read reads data from the ring buffer by a consumer

func (*RingBuffer[T]) Write

func (rb *RingBuffer[T]) Write(value T) error

Write writes data into the ring buffer by a producer.

It explicitly boxes the value on the heap to ensure the pointer remains valid, avoiding reliance on compiler escape analysis for safety.

type Slot

type Slot[T any] struct {
	// contains filtered or unexported fields
}

Slot represents a single slot in the ring buffer

Jump to

Keyboard shortcuts

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