Skip to content
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

Proposal: allow "stackalloc" class references' array when using span #33960

Closed
ygc369 opened this issue Mar 23, 2020 · 4 comments
Closed

Proposal: allow "stackalloc" class references' array when using span #33960

ygc369 opened this issue Mar 23, 2020 · 4 comments

Comments

@ygc369
Copy link

ygc369 commented Mar 23, 2020

Currently the following code is disallowed:

span<object> arr = stackalloc object[10];

But I think that this should be allowed, stackalloc object[10] should not mean to allocate 10 objects on the stack, it should mean to allocate 10 object references on the stack (all initialized to null).
I have posted this proposal in csharplang repo(dotnet/csharplang#3294), but someone told me this is a runtime issue, because the corresponding IL instruction only supports struct now. So I think this proposal need CLR support.

@jkotas
Copy link
Member

jkotas commented Mar 23, 2020

Related / duplicate: #25423

@ygc369
Copy link
Author

ygc369 commented Mar 23, 2020

@jkotas

Related / duplicate: #25423

I think they are different. That proposal focus on "safety", but my proposal focus on "freedom" or "flexibility".

@jkotas
Copy link
Member

jkotas commented Mar 23, 2020

Both of the proposals are solving the same problem. #25423 has the nice property that it also solves problems with stackalloc in general.

@ygc369 ygc369 closed this as completed Mar 23, 2020
@GSPP
Copy link

GSPP commented Mar 31, 2020

If the runtime becomes capable of stack allocating references, this should just work with the normal stackalloc keyword. #25423 would not include that work.

@ghost ghost locked as resolved and limited conversation to collaborators Dec 10, 2020
@tannergooding tannergooding removed the untriaged New issue has not been triaged by the area owner label Jun 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants