Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Any idea on how it compares to std::span in C++. .NET is indeed quite fast nevertheless, (at least since 6).


C++ 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


  bcmp() is identical to memcmp(3); use it instead.


This is what we call "a lie". There's a reason the compiler generates bcmp instead.


I think it is substantially equivalent to C++ std::span (essentially a typed pointer + length pair).


Span<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.


You 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/




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: