This proposal introduces a new WinRT interface, IReserveableVector, that extends IVector<T> with a capacity-reservation method. It allows callers to preallocate storage before bulk insertion, reducing repeated reallocations and improving performance for append-heavy scenarios.
Motivation
IVector<T> exposes size and element access but no way to reserve capacity. When an app appends many elements, the underlying implementation may grow and copy repeatedly. A Reserve method gives callers explicit control over allocation, similar to std::vector::reserve or .NET List<T>.Capacity.
std::vector::reserve can make push_back more than twice as fast, and it can also make IVector::Append more than twice as fast. This usage has existed in C++ for thirty years, but WinRT lacks it. C++/WinRT and C#/WinRT should support implementing this interface when implementing IVector.
Proposed Interface
interface IReserveableVector
{
void Reserve(UInt32 capacity);
}
Behavior
Reserve(capacity) ensures the vector can hold at least capacity elements without reallocation.
- If
capacity is less than or equal to the current capacity, the call is a no-op.
- If
capacity is smaller than Size, it does not shrink the vector; existing elements are preserved.
- The method does not change
Size or insert elements.
This proposal introduces a new WinRT interface, IReserveableVector, that extends
IVector<T>with a capacity-reservation method. It allows callers to preallocate storage before bulk insertion, reducing repeated reallocations and improving performance for append-heavy scenarios.Motivation
IVector<T>exposes size and element access but no way to reserve capacity. When an app appends many elements, the underlying implementation may grow and copy repeatedly. AReservemethod gives callers explicit control over allocation, similar tostd::vector::reserveor .NETList<T>.Capacity.std::vector::reservecan makepush_backmore than twice as fast, and it can also makeIVector::Appendmore than twice as fast. This usage has existed in C++ for thirty years, but WinRT lacks it. C++/WinRT and C#/WinRT should support implementing this interface when implementingIVector.Proposed Interface
interface IReserveableVector { void Reserve(UInt32 capacity); }Behavior
Reserve(capacity)ensures the vector can hold at leastcapacityelements without reallocation.capacityis less than or equal to the current capacity, the call is a no-op.capacityis smaller thanSize, it does not shrink the vector; existing elements are preserved.Sizeor insert elements.