4 ms·
Spans are not a low-level feature, they are a general purpose container type representing a slice, like &[T] in Rust. That's it. Analyzers will nudge you to us
by neonsunset 2y ago
Spans are not a low-level feature, they are a general purpose container type representing a slice, like &[T] in Rust. That's it. Analyzers will nudge you to use them naturally next time you write int.Parse(text.Substring(0, 4)) to replace it with int.Parse(text.AsSpan(0, 4)) - you don't need an intermediate string, just a slice of it. But because they can wrap any memory, you can now pass anything to int.Parse that can produce a span of chars or bytes: stackalloc, pointer + length from C/C++, an array, a string, etc. all unified with a single type.
Vectorization techniques themselves are not C# specific, but dotnet/runtime does have an introductory guide that demonstrates their "basic" use-case:
https://github.com/dotnet/runtime/blob/main/docs/coding-guidelines/vectorization-guidelines.md https://github.com/dotnet/runtime/blob/main/docs/coding-guid...