Namespace: Rx – Class: CRxArrayChar – Header: Rx.Core/RxArrayTypes.h

CRxArrayChar::Reserve Method

C++
void Reserve(size_t nNewElementCount)

Increase the capacity of the array to a value that's greater or equal to nNewElementCount. If nNewElementCount is greater than the current capacity, new storage is allocated, otherwise the method does nothing.

If nNewElementCount is greater than capacity, all iterators, including the past-the-end iterator, and all references to the elements are invalidated. Otherwise, no iterators or references are invalidated.

Reserve cannot be used to reduce the capacity of the array, to that end ShrinkToFit() is provided.

Correctly using Reserve can prevent unnecessary reallocations, but inappropriate uses of Reserve (for instance, calling it before every PushBack() call) may actually increase the number of reallocations (by causing the capacity to grow linearly rather than exponentially) and result in increased computational complexity and decreased performance.

Parameters

[size_t] nNewElementCount

The new element count.