Replies: 2 comments
-
Where did you run into this being a problem in practice? |
Beta Was this translation helpful? Give feedback.
0 replies
-
similar issue #53128 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Background and Motivation
List<T>
has aCapacity
property, which core sounds with its underlying array’s length. It defaults to 4, but can be manually set in a constructor overload or in the aforementioned property.When adding items,
EnsureCapacity
will, if needed, grow the capacity so additional items fit. This is currently hardcoded to double the previous value. I.e., if you add a fifth item, the capacity becomes 8. Doubling was presumably chosen as an adequate compromise for typical use. Note, however, that capacity increases require copying the entire existing list to a new internal array.Proposed API
Usage examples
In most cases, you’ll use
List<T>
as before. The defaultCapacityGrowthPercentage
is 100; the capacity grows by 100% each time.For cases where you anticipate a list that
you might set it to a much lower value:
Beta Was this translation helpful? Give feedback.
All reactions