Skip to content
Omnikalc

Dynamic array growth calculator

Enter the growth factor, the initial capacity and the number of appended elements to get the number of resizes, the total copies, the amortized cost per append and the unused capacity.

Updated on
Your inputs
slots

Value out of range

Value out of range

Results

Number of resizes

16

Final capacity
1,048,576
Elements copied in total (at most)
1,048,560
Copies per append (amortized)
1.049
Unused capacity at the end
4.6 %
Peak memory during the last resize (× data)
1.57 ×
Moderate peak memory

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.

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.

Frequently asked questions

Why is appending constant time on average?

Each resize copies the whole array, but resizes happen less and less often because the capacity grows geometrically. The copies add up to a geometric series c0 × (g^r − 1) / (g − 1), which is proportional to the final size, so the cost per append stays a constant, about 1 / (g − 1) copies.

Which growth factor is best?

There is a trade-off. A large factor such as 2 means fewer copies, about one per append, but up to half of the capacity can be unused. A small factor such as 1.5 copies about twice per append and wastes less. A factor below 2 also lets freed blocks be reused by later buffers, which is one reason some libraries pick 1.5.

How can I avoid the resizes?

If you know the final size in advance, reserve it at the start. The array is allocated once, there is no copy and no wasted capacity beyond what you asked for. Most languages offer this with a reserve, with-capacity or ensureCapacity call.

Was this calculator helpful?

Thanks for your feedback!

Results are estimates provided for information purposes. They do not replace professional advice.