-
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 Span<T>(ref T obj) constructor #24615
Comments
This is not doing GC tracking correctly. It is not ok to call |
I think that is a problem for the caller, just like it is for the pointer ctor and This ctor would be at least as safe as the pointer one. |
@VSadov What were the problems with wrapping locals in Span? |
📝 Related to dotnet/csharplang#992 |
There is a problem with wrapping a ref parameter. For example any time a local is passed by ref to a method that returns span, that span would be not returnable. |
We discussed some support for wrapping single variable into a span. The issue gets pretty complex when you need to ensure life times. It seems simple - if you wrap a local, then the resulting span value cannot leave the local's scope, if you wrap a heap location, then it can escape anywhere. Where it becomes a problem is when ref parameters/returns/local are involved.
We may need a special language feature that specificaly "takes a ref and wraps it in a span", and we will track result as not escapable, unless we are sure the input ref was a heap ref. Basically - this functionality may be introduced, but that would not be via a call to an ordinary method/constructor. |
I guess the comment would be more useful in the discussion for dotnet/csharplang#992 |
Noticed |
It is a small annoyance that to use a span/readonly span with a single instance of a value type you have to mark the assembly as unsafe (or call some helper code that does so)...
It would be nice if I had a constructor that did this for me:
And same for
ReadOnlySpan<T>
Or is there a better way to do this?
The text was updated successfully, but these errors were encountered: