12.2. Dynamic Arrays
The new
and delete
operators allocate objects one at a time. Some applications, need the ability to allocate storage for many objects at once. For example, vector
s and string
s store their elements in contiguous memory and must allocate several elements at once whenever the container has to be reallocated (§ 9.4, p. 355).
To support such usage, the language and library provide two ways to allocate an array of objects at once. The language defines a second kind of new
expression that allocates and initializes an array of objects. The library includes a template class named allocator
that lets us separate allocation from initialization. ...
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.