Buffer

class Buffer(val id: String)

Append-only text store behind the named, persistent Probe channels — its only consumer — held as immutable segments. Content is never dropped; the channel stays unbounded.

A single StringBuilder puts two O(channel) operations on the WRITER's thread, which is a patch handler's, i.e. a tick thread: the doubling realloc, and the Latin-1 -> UTF-16 inflate that the first non-ASCII char forces over the whole array. Freezing at SEGMENT_CHARS bounds both by that constant.

The size check runs AFTER the append, so no write is split: every segment ends at the newline appendLine put there, and a consumer splitting segments into lines never sees a torn one.

A runaway channel is reported to Constants.LOG and nowhere else: Probe's consumer is script CODE, so an injected note would land in whatever parses the result, and a cap would make every read ask "was that all?".

Constructors

Link copied to clipboard
constructor(id: String)

Types

Link copied to clipboard
private object Companion

Properties

Link copied to clipboard
private val frozen: ArrayList<String>

Frozen segments, oldest first, immutable once added. A plain list read under lock, not a copy-on-write one: freezes are frequent and reads rare, so COW would charge the writer O(segments) per freeze to save the reader a snapshot.

Link copied to clipboard
private val id: String
Link copied to clipboard
private val lock: Any
Link copied to clipboard
private var sb: StringBuilder
Link copied to clipboard
private var warnAt: Int

Next frozen size to warn at, doubling after each one so a runaway escalates instead of flooding. Under lock.

Functions

Link copied to clipboard
fun appendLine(x: Any?)
Link copied to clipboard
fun clear()
Link copied to clipboard

segments and empty in one step, so an append landing mid-consume is not lost the way a segments() + clear pair loses it.

Link copied to clipboard
private fun freezeTail()

Move the unfrozen tail into frozen, if there is one. Under lock.

Link copied to clipboard
private fun reset()

Back to the initial shape, small builder included: a drained channel may never fill again.

Link copied to clipboard

Snapshot, oldest first — not a live view. Copies segment REFERENCES; only the unfrozen tail is materialized, bounded by SEGMENT_CHARS.

Link copied to clipboard
private fun snapshotLocked(): List<String>