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 ¶
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 ¶
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 ¶
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.