The Drum Forgets Last Week at Midnight
The barograph drum rotates once every eight days, and when it completes its circuit, the pen starts writing over last week’s pressure. This is exactly what a circular buffer does in software: a fixed-size array where the write pointer wraps around to the beginning when it reaches the end, silently overwriting the oldest data. Victorian meteorologists invented a hardware ring buffer in brass and paper.
In Kotlin, the modulo operator handles the wraparound:
class RingBuffer(private val size: Int) {
private val data = IntArray(size)
private var head = 0
fun write(value: Int) {
data[head] = value
head = (head + 1) % size
}
fun oldest(): Int = data[head]
fun dump() = (0 until size).map { data[(head + it) % size] }
}
The (head + 1) % size expression is the whole trick. When head reaches 6 in a 7-element buffer, the next write goes to position 0. No bounds checking, no array resizing, no memory allocation after initialisation. The 1970s loved this pattern because RAM cost real money.
Forth makes the circularity even more visible:
7 CONSTANT DAYS
CREATE drum DAYS CELLS ALLOT
VARIABLE pen
: inscribe ( pressure -- ) pen @ CELLS drum + ! pen @ 1+ DAYS MOD pen ! ;
: week DAYS 0 DO pen @ I + DAYS MOD CELLS drum + @ . LOOP ;
That pen @ 1+ DAYS MOD pen ! line — fetch the pointer, increment, modulo by buffer size, store back — is the same logic as the Kotlin version, just in postfix notation. The word inscribe writes a pressure reading; week prints all seven values starting from the oldest.
Circular buffers dominate anywhere you need recent history but can’t afford unbounded growth: audio sample buffers, network packet queues, kernel log rings, undo stacks with limited depth. The Linux kernel’s dmesg buffer has been circular since the early days. Your shell’s command history is usually a ring.
The barograph’s mechanical advantage is that the “overwrite” is literally just the pen moving back to the same position on the drum. The old trace stays faintly visible under the new one until you change the paper. Software doesn’t usually give you that ghosting — when position 0 gets overwritten, the old value is gone. Some embedded systems explicitly log a “buffer wrapped” marker so you know history was lost. The brass drum doesn’t warn you. It just keeps drawing.