arena

package
v0.10.2 Latest Latest
Warning

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

Go to latest
Published: May 21, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package arena provides a bump-allocator backed by a single contiguous []byte. The arena hands out []float64 and []byte slices that share that backing buffer; resetting the arena invalidates every slice it ever returned.

Use cases inside Pulse:

  • Streaming iterator scratch: each row needs small typed buffers (8-byte field-decode scratch, transient wide-value slots). Bumping into a shared buffer avoids the per-row map/slice make().
  • Batch processing: when the row count is known up front, one Grow call up front + AllocF64s per aggregator working buffer collapses N independent makes into one.

Lifetime contract: anything returned from AllocF64s/AllocBytes lives until the next Reset(). After Reset(), every previously-returned slice header is still valid Go memory but its bytes will be overwritten by subsequent allocations. Callers MUST NOT retain slices across Reset.

Concurrency: Arena is not safe for concurrent use. Callers that fan allocations across goroutines must hold one Arena per goroutine.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Arena

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

Arena is a bump allocator backed by a single byte buffer.

func New

func New(initialBytes int) *Arena

New creates an Arena with the given initial capacity in bytes. Capacity grows on demand when Alloc requests exceed available space; pre-sizing to the expected high-water mark avoids the grow path.

func (*Arena) AllocBytes

func (a *Arena) AllocBytes(n int) []byte

AllocBytes returns a []byte of length n drawn from the arena. The returned slice is zeroed (Go-init semantics) and aliased to the arena backing buffer.

func (*Arena) AllocF64s

func (a *Arena) AllocF64s(n int) []float64

AllocF64s returns a []float64 of length n drawn from the arena. The underlying memory is 8-byte aligned because Alloc places f64 regions at offsets that are multiples of 8.

func (*Arena) Cap

func (a *Arena) Cap() int

Cap returns the arena's current capacity in bytes.

func (*Arena) Len

func (a *Arena) Len() int

Len returns the number of bytes currently allocated since the last Reset.

func (*Arena) Reset

func (a *Arena) Reset()

Reset returns the offset to zero. All slices previously returned by Alloc* remain valid Go memory but their contents are no longer owned by the caller — subsequent allocations will overwrite them.

Jump to

Keyboard shortcuts

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