Skip to content

· 4 min read

Goose keeps the address

Goose lets an array grow around stable references by giving storage a stricter shape. The interesting part is what that shape asks of the rest of the program.

A goose stands beside a compartmented brass trough containing colored stones and a crank at one end.
Illustration generated with GPT Image

Growing an array can become a surprisingly social operation. Eventually an element arrives, the storage moves, and everyone holding an address into the old allocation needs to hear about it. A handle table can keep the peace. So can an extra pointer per object. Wouter van Oortmerssen's Goose caught my attention by arranging the storage so the existing elements can stay where they are.

The small example I would start with is an array of records. Keep a reference to the first record, append another, then update the first through that reference. It is an ordinary thing to want when building a graph or collecting work that refers to earlier work.

A reference survives a push
struct Item { score: i64 }fn main() {    var entries: Item[>..] = [];    let saved: Item& = entries.push(Item { 7 });    entries.push(Item { 12 });    saved.score = 9;}
  1. 1[>..] declares a grow-only array.
  2. 2push returns a reference to the inserted record.
  3. 3The earlier record is still at the address saved points to.
A smaller adaptation of Goose's memory example.

The useful promise here is very specific: appending to this container preserves the address already handed out. That lets a reader understand the last assignment without following a separate identity scheme through the program.

The promise lasts while the owning storage is alive. A reference still cannot escape into some longer-lived object and survive its owner. That boundary matters when drawing the graph: the arrows may cross between records, but they need storage that outlives their use.

Leave room at the end#

Goose's memory model separates the native call stack from data stacks backed by reserved virtual address space. Pages are committed as needed. Each data stack has a bump pointer, and at most one live resizable value occupies its growing end. Two simultaneously growing containers need separate stacks. The compiler works out how many stacks the program requires.

I picture a long workbench with an empty stretch beyond the current project. Adding another piece uses that stretch. Placing somebody else's project immediately after it would spoil the arrangement, which explains why the rule about one growing value matters. Stable addresses follow from keeping that room available.

The tutorial's account of storage follows the idea through allocation and cleanup: growth advances a pointer; leaving the owning scope restores the earlier position. Locals with separate lifetimes can reuse storage. The large reservation is address space, so its size should not be mistaken for resident memory.

That makes temporary work especially easy to imagine. Parse a chunk, build the intermediate values needed for that chunk, finish, and leave the scope. I like being able to point at a closing brace and explain why a whole batch of storage becomes available again.

The shape reaches into the algorithm#

The same specification limits recursion: a function in a recursive cycle cannot keep a nonfixed local alive across a call back into that cycle. Storage that must survive the descent belongs outside the cycle and is passed in. Arrays whose elements have variable sizes also require sequential traversal; direct random indexing needs a separately maintained index.

Those restrictions would affect how I wrote a tree builder. A recursive routine that creates its own growing buffer before visiting children would need another arrangement. Keeping the output pool in the caller might improve the design. Sometimes it would just be extra work. Either outcome belongs in an evaluation of the language alongside the pleasant append example.

For less orderly lifetimes, the reusable-pool tutorial describes slots that remain valid values of their declared type after release. Reusing a slot can make an old reference observe a different record. Memory remains type safe, while logical identity becomes the program's responsibility. A stale enemy handle can still select the wrong enemy.

Before choosing Goose for a larger tool, I would build one representative parser or graph pass and count the accommodations: extra index tables, buffers moved outside recursive calls, and places that need explicit identity checks. I would measure resident memory and iteration time too. The address staying put is a good starting point; the next question is how naturally the rest of my program fits around it.