Capacity is the number of elements an array has room to hold. It differs from current size: an array may have space for more elements than it currently stores. section 2.11 section 5.2
Capacity affects what happens when elements are added or removed:
- A static array has a fixed capacity. When it is full, insertion must report failure; adding capacity later requires allocating another array and moving elements. section 2.11 section 5.2
- A dynamic array can grow when full, commonly by doubling its capacity. It can also shrink after removals; one described strategy halves capacity when only a quarter is filled. section 5.14
- Extra capacity can avoid frequent resizing, but allocating far more space than needed wastes memory. If you can estimate usage, an initial capacity can reserve space in advance. section 5.16 section 5.2
A changing workload
An order-tracking array might grow to hold 10,000 open orders during a holiday peak, then keep that capacity after orders close. Without shrinking, most allocated space could sit unused when only about 100 orders remain. section 5.11




