Skip to content
AITroveRead. Build. Understand.
Make this comfortable

Project: audit four reusable storage contracts

Last updated: 3 Oct 202630 min read
project
IntermediateBy AITrove Editorial

A maintenance service needs temporary parse bytes, variable-sized report buffers, power-of-two page units, and fixed-shape incident records. Assign one structure to each workload and write down who owns a live allocation. Build a small reference ledger with occupied intervals for the first three structures and live coordinate-generation pairs for the slab cache. After each operation, compare coverage, overlap, free capacity, and stale-handle behavior against that ledger. Treat a failed allocation as a state-preserving event. Account for padding and rounded blocks separately from requested payload sizes.

Acceptance trace

Write PUMP-47 before an arena checkpoint, reserve a temporary twelve-byte span, rewind, and verify the earlier tag survives while the old temporary handle fails. In a 64-unit first-fit pool, allocate 13 and 19, release both, and allocate 24 at start zero with 40 units free. In a 128-unit buddy pool, allocate 13 and 19, release both, and recover one free root block. In a three-slot slab, allocate four incidents, reuse one released coordinate, and reject its old generation.

Expected review record

Output
arena-stable=PUMP-47
first-fit-start=0
buddy-root=128
slab-stale=True

Boundary and cost review

Try an arena allocation that exceeds remaining aligned capacity and ensure the cursor does not move. Exercise a free pool with enough total free units but no contiguous fit. For every buddy release, verify that only a true same-order partner merges, and that the final free and allocated blocks cover the root exactly. Fill two slab pages, release one handle twice, then allocate into its old coordinate and prove the first handle stays invalid. Explain why zeroing changes the arena allocation cost, why sorting changes free-list release cost, and why min over a set affects this buddy implementation.

Common Mistakes

  • Do not confuse a reused address with a reused object identity.
  • Do not count adjacent live space as a free interval.
  • Do not merge unequal buddy orders.
  • Do not infer that an empty slab page has been returned to the host.

Connected lessons

data structures
projects
Storage details