-
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
API Proposal: ValueStack<T> and other stack-allocated collection types #61456
Comments
Tagging subscribers to this area: @dotnet/area-system-collections Issue DetailsBackground and motivationFixed-size stack-allocated collection types possibly backed by the given API Proposalnamespace System.Collections.Generic
{
public ref struct ValueStack<T>
{
public void ValueStack(Span<T> storage); // implies a fixed size
public void Push(T value);
public T Pop();
public T Peek();
// other applicable members from Stack<T>
}
} API Usagevar stack = new ValueStack<int>(stackalloc int[10]);
stack.Push(42); Alternative DesignsNot exactly "alternatives", but other variables such as ValueQueue or ValueDeque are most likely desirable to add. RisksNo response
|
This sounds like it would suffer from the same issue as |
Is there a discussion/issue about the compiler's side of things you can link to? |
It seems to mostly just be a discussion so far: dotnet/csharplang#859. I'd imagine we should write a proper proposal and try to get some traction if we wanted to unblock this. |
So much happening with span safety https://github.com/dotnet/csharplang/blob/main/proposals/low-level-struct-improvements.md I wonder if any of that could address this issue? Really looking forward for a proposal on "move-only structs" |
Would the work on |
Likely not and on top of that My TerraFX project provides a
These types are largely meant for scenarios where you need something like a
|
Background and motivation
Fixed-size stack-allocated collection types possibly backed by the given
Span<T>
for local use.API Proposal
API Usage
Variants
Other variants such as
ValueQueue<T>
orValueDeque<T>
are most likely desirable to add.One that .NET is currently lacking is a "circular-buffer" type which make sense to have a span-backed implementation for, due to the inherent fixed-size.
Risks
No response
The text was updated successfully, but these errors were encountered: