pool

package
v0.52.0 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2026 License: MPL-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package pool provides allocation-efficient data structures for high-throughput DDS workloads on embedded and edge hardware.

BytePool recycles fixed-capacity byte slices via sync.Pool, reducing GC pressure on fast publish paths that would otherwise allocate a new buffer per sample.

SampleBuffer is a fixed-capacity ring buffer of dds.Sample values. It provides bounded, allocation-free queuing that can be used as a staging area between a subscriber channel and an application processing loop.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BytePool

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

BytePool is a sync.Pool-backed pool of byte slices with a fixed capacity. Use Get to obtain a zero-length, pre-allocated buffer, write into it, and return it with Put when done. The pool prevents per-sample heap allocations on hot publish paths.

func New

func New(size int) *BytePool

New returns a BytePool whose Get method returns slices with the given capacity. Callers may append up to size bytes without triggering a new allocation.

func (*BytePool) Get

func (p *BytePool) Get() []byte

Get retrieves a zero-length, pre-allocated byte slice from the pool. The caller must call Put when done to return the buffer.

func (*BytePool) Put

func (p *BytePool) Put(buf []byte)

Put returns buf to the pool. Buffers smaller than the pool's configured size are discarded so that the pool never accumulates undersized slices.

type SampleBuffer

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

SampleBuffer is a fixed-capacity concurrent ring buffer of dds.Sample values. It provides bounded, allocation-free queuing suitable for use as a staging area between a subscriber channel and an application processing loop running at a different rate.

func NewSampleBuffer

func NewSampleBuffer(capacity int) *SampleBuffer

NewSampleBuffer returns a SampleBuffer with the given capacity. A capacity of ≤ 0 uses the default of 64.

func (*SampleBuffer) Cap

func (sb *SampleBuffer) Cap() int

Cap returns the buffer's maximum capacity.

func (*SampleBuffer) Len

func (sb *SampleBuffer) Len() int

Len returns the number of samples currently held in the buffer.

func (*SampleBuffer) Pop

func (sb *SampleBuffer) Pop() (dds.Sample, bool)

Pop removes and returns the oldest sample. Returns false if the buffer is empty.

func (*SampleBuffer) Push

func (sb *SampleBuffer) Push(s dds.Sample) bool

Push adds s to the ring buffer. Returns false if the buffer is full.

Jump to

Keyboard shortcuts

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