Growing an allocation is cheap when the block right after it is free - just absorb it. Today Realloc extends into a following free block when there is room, keeping the same offset and the same data.
Grow an allocation in place by absorbing the following free block when it is large enough.
When a request grows, the happy path is that the block immediately after it is free and large enough to cover the shortfall. Then realloc can stay put: absorb the free successor (pull it from the free list, add its size), and the enlarged block holds the bigger payload at the same offset - no copying, the data never moves. If the combined block is bigger than needed, split the excess back off as before.
This is the win that makes a growing loop (append, append, append) cheap when the allocation sits next to free space: each growth just eats a little more of the neighbour. It only works when the neighbour is free and big enough, though. When it is not - an allocated block sits right after, or the free block is too small - the allocation genuinely has to move somewhere it fits. That relocate-and-copy fallback is the next lesson.
// growing: look at the next blocknextOff := off + sizeif nextOff < len(a.buf) {if nsize, nalloc := a.blockAt(nextOff); !nalloc && size+nsize >= need {a.unlink(nextOff)size += nsize // absorb the successorif size-need >= minBlock {a.putBlock(off, need, true)a.freeBlock(off+need, size-need)} else {a.putBlock(off, size, true)}return payload, nil}}