-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add API to read, set and ensure capacity of Stack<T> and Queue<T> #44801
Comments
Tagging subscribers to this area: @eiriktsarpalis, @jeffhandley Issue Details
|
Personally, I would prefer the alternative design that you propose for a couple of reasons:
|
FWIW I just updated my PriorityQueue API proposal to contain a |
Btw, it seems that the right signature is |
I'm sorry, it's my first time proposing an API. What I'm supposed to do? Edit my initial post to use |
Yes please :-) |
Done |
namespace System.Collections.Generic
{
public partial class List<T>
{
public int EnsureCapacity(int capacity);
}
public partial class Stack<T>
{
public int EnsureCapacity(int capacity);
}
public partial class Queue<T>
{
public int EnsureCapacity(int capacity);
}
} |
Hi @eiriktsarpalis, this was assigned to you but mark as up for grabs, so not sure can external guys pick to implement or not? |
Hi @lateapexearlyspeed I had myself assigned for API review purposes. Yes this would be open to external contributes, would you be interested in taking this? :-) |
@eiriktsarpalis Yes, I would try this, thanks :) |
Background and Motivation
Several dynamic collections offer APIs to check the capacity of their underlying arrays and offer ways to increase it if you know the necessary size ahead of time. For example
List<T>.Capacity
,HashSet<T>.EnsureCapacity(int)
orDictionary<TKey, TValue>.EnsureCapacity(int)
.This allows developers to reserve the necessary space of those collections before performing a heavy workload, and so reduce the number of times those collections must auto-resize, thus reducing GC pressure and CPU time.
However, not all the common collections offer these APIs.
Proposed API
I propose to add the following methods:
Usage Examples
Risks
It increases the surface API.
The text was updated successfully, but these errors were encountered: