#preallocation
Wiki
›
Algorithms
›
02. Data Structures
›
1. Core Data Structures and Operations
›
1.1 Arrays and Dynamic Arrays
›
Capacity Reservation
Capacity Reservation Capacity reservation allocates enough storage before elements are inserted. It separates allocated capacity from logical size so that append operations can use existing memory. You use it when the approximate final size is known and repeated resizing would waste time. Problem Given a dynamic array $A$, reserve enough capacity for at least $m$ elements while preserving existing elements. The invariant is: $$ size(A) \le capacity(A) $$ After reservation:...