Time to drive the whole allocator API through one scripted sequence - malloc, calloc, free - and check the exact heap that results. It is a dress rehearsal for the capstone and a demo you can run end to end.
Run a fixed allocate-and-free script and assert the exact resulting layout.
This lesson writes no new allocator code - it uses what you have. A short script
allocates two blocks, stores a byte, frees the first, then calloc’s a block of the
same size. Tracing it confirms the pieces cooperate: the freed block at offset 0 is
the one calloc reuses (so a and c share offset 8), the byte written under
a’s ownership is scrubbed back to zero by calloc, and the final layout is
exactly three blocks.
Running a whole workload and asserting one Dump string is how you gain confidence
that malloc, free, split, coalesce, and calloc all agree with each other - the same
shape of check the capstone will make at the very end, only larger. The core
allocator is done; the last chapter makes it faster with size-class bins and
adds the self-checks that prove a heap is not corrupt.
a, _ := al.Malloc(8) // 8 -> block (0,24)al.Set(a, 0x99)b, _ := al.Malloc(16) // 32 -> block (24,32)al.Free(a) // block 0 free againc, _ := al.Calloc(8) // 8 -> reuses block 0, zeroed// Dump == "0:24:A|24:32:A|56:40:F"