-
Notifications
You must be signed in to change notification settings - Fork 1k
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
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]: stackalloc inside ref struct #6631
Comments
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label. |
Your example of a constant-sized stackalloc can already be achieved like this: public ref struct CustomIterator<T> where T: unmanaged
{
private Span<T> _data;
public CustomIterator(Span<T> data)
{
_data = data;
}
} public static void Something()
{
var iterator = new CustomIterator<byte>(stackalloc byte[128]);
} |
This belongs to dotnet/csharplang, where this is effectively a part of #1502. |
This is partially a solution but you dont always want to pass that stackalloc from the outside, cause you may need it for specific calculations and you know exactly the length at compile time inside the ref-struct. RIght now i have such an instance where i dont want outsiders to define what and how large the storage shall be and even then allow that thing outsiders to even utilize. Its nice that you even have the chance to do that, but its really not an all case scenario solution. I would think that, since we can have |
Another flaw with your design is that you would allow potentially evrything to be passed, which can be dangerous. So this is prevented with my api-choice aswell. PS: I shall remove the where T: unmanaged constraint because i need a 3-tuple insidethat enumerator; So i need a fixed-size pool of that, which is sadly not possible with the usual "fixed T[10]" cause it only can contain primitive datatypes. |
It would seem to me that a better solution would be to make this possible then: public ref struct CustomIterator<T> where T: unmanaged
{
private fixed T data[<const size >];
} Plus to be able to treat |
yea fixed does all that, except like u cant use ValueTuples with it |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
Background and motivation
You can do a lot of things with it when you can store arrays inside the restricts which are stack allocated and have no need to exist longer than they have to.
API Proposal
API Usage
Alternative Designs
No response
Risks
Not AFAIK
The text was updated successfully, but these errors were encountered: