Growing Pains: realloc and Automatic Capacity Management

Post 2 of the Dynamic Arrays in C series · Full source code Where We Left Off In Post 1 we built an array that does three things: allocate a fixed buffer, push integers into it, and free everything when we’re done. It works, until it doesn’t. The moment the user pushes one element more than the initial capacity allows, array_push returns -1 and refuses to cooperate. The array is full and there’s nothing we can do about it. ...

May 28, 2026 · 14 min · pablo

Hello, Array: malloc, free and Manual Bookkeeping

Post 1 of the Dynamic Arrays in C series · Full source code The Problem No One Starts With You have five integers. You put them in an array: 1 int numbers[5] = {10, 20, 30, 40, 50}; Done. C gives you a contiguous chunk of 20 bytes on the stack, indexed from 0 to 4, and life is good. Now your user wants to add a sixth integer. What do you do? You can’t resize a stack array. Its size was baked into the binary at compile time, the compiler saw 5, calculated 20 bytes, and that’s the space your function’s stack frame has. There’s no negotiation. You could declare int numbers[1000] and hope it’s big enough, but hope is not a memory management strategy. ...

May 24, 2026 · 18 min · pablo