Skip to content

Proposal: Add IReserveableVector to WinRT #6768

Description

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions