Item 37. Array Allocation
Most C++ programmers know to keep the array and nonarray forms straight when allocating and deallocating memory.
The reason it’s important to keep these functions properly paired is that array allocation and deallocation use different functions from nonarray allocation and deallocation. A new expression does not use operator new
to allocate storage for an array. It uses array new. Similarly, a delete expression does not invoke operator delete
to free an array’s storage; it invokes array delete. To be precise, when you allocate an array, you’re using a different operator (new[]
) than you do when you allocate a nonarray ...
Get C++ Common Knowledge: Essential Intermediate Programming 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.