4 ms·
Any idea on how it compares to std::span in C++. .NET is indeed quite fast nevertheless, (at least since 6).
by npalli 2y ago
Any idea on how it compares to std::span in C++.
.NET is indeed quite fast nevertheless, (at least since 6).
- loeg 2y agoI think it is substantially equivalent to C++ std::span (essentially a typed pointer + length pair).
- Dwedit 2y agoSpan<T> is a "ref struct" type, and thus has a lot of restrictions on its use. For instance, you can't have one as a field or property in a class, so you can't assign it to outside of the scope that it was declared in.
- neonsunset 2y agoYou can assign the span to an out of scope variable as long as it does not violate the scoping of the memory referenced by that said span. The closer primitive to C#'s Span<T> is Rust's &mut [T] since both are subject to lifetime analysis (of course the one in C#[0] is quite rudimentary in comparison to Rust). [0]: https://em-tg.github.io/csborrow/ https://em-tg.github.io/csborrow/
- jeffbee 2y agoC++ std::span doesn't have comparison operators at all. If you were to write an equality operator you might use memcmp, in which case it will be exactly the same as memcmp, which LLVM will helpfully reinterpret as bcmp for best performance. See for example the difference between std::string::operator== and just calling memcmp yourself: https://godbolt.org/z/qn1crox8c https://godbolt.org/z/qn1crox8c
- deleted 2y ago[deleted]