The dynamic array growth calculator gives the number of resizes, the elements copied, the amortized copies per append and the unused capacity of an array that grows by a fixed factor while elements are appended.
How the calculation works
- Pick the growth factor and enter the initial capacity.
- Enter the number of appended elements.
- The calculator gives the resizes, the final capacity, the copies, the copies per append, the unused capacity and the peak memory.
Example
Appending 1,000,000 elements to an array that starts at 16 slots and doubles needs 16 resizes, to a final capacity of 1,048,576. The copies add up to 1,048,560, which is 1.049 per append, and 4.6 % of the capacity is unused at the end. During the last resize, the old and the new buffers coexist, so the peak memory is 1.57 times the data.
Why it matters
The calculator helps programming students and developers to compare the growth strategies of vectors, lists and string builders, and to decide when reserving capacity is worth it.
Good to know
The numbers are an upper bound, because the copy of a resize only moves the elements actually stored, which is the full old capacity when a resize happens. The cost of an individual append is not constant: the one that triggers a resize costs as much as the whole array, which matters for latency-sensitive code. For real-time systems, a fixed-capacity buffer or an incremental resize avoids those spikes. Memory allocators may also round sizes up to a bucket, and a large realloc can sometimes extend in place, with no copy at all. The same analysis applies to hash tables that double their bucket array when the load factor is exceeded, and to the growth of string buffers when concatenating.
Related tools
The binary search calculator covers lookups in sorted arrays, the hash collision calculator describes hash tables, the LLM memory calculator sizes large buffers and the page table size calculator shows how memory is organized.