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: syntactic sugar for initializing Span<char> by stackalloc with string literal #1947
Comments
Why? Are there any cases where memory consumed by string literals is an issue? |
@svick I read this as wanting to initialize the space from a string literal but then using it as scratch space. |
Oh, so the equivalent of the following code? string s = "initial characters";
Span<char> span = stackalloc char[s.Length];
s.AsSpan().CopyTo(span); Is that actually so common that it needs syntactic sugar? |
I do not think so. I did not even know about Span in c#. |
@svick That's what I understood @acid-chicken to mean. I haven't run into this pattern before, though I have been in situations where I'd copy a literal to the beginning of a longer buffer. If the stack space isn't going to be mutated after copying the literal into it, I'd just get the pointer to the literal directly without allocating stack space and doing the copy (or use ReadOnlySpan). |
Summary
Provide a syntactic sugar which initializes Span and ReadOnlySpan with stackalloc keyword by string literal.
Design
will be converted to
Choices
Syntax Style
or
or
or other?
Also Support
char[]
Also adding syntactic suger for
char[]
initializer?The text was updated successfully, but these errors were encountered: