Members to Manage Capacity
The vector
and string
types provide members, described in Table 9.10, that let us interact with the memory-allocation part of the implementation. The capacity
operation tells us how many elements the container can hold before it must allocate more space. The reserve
operation lets us tell the container how many elements it should be prepared to hold.
Note
reserve
does not change the number of elements in the container; it affects only how much memory the vector
preallocates.
Get C++ Primer, Fifth Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.