3 ms·
What about bounds checking and stuff? Sorry for my ignorance on the matter.
by thegeomaster 12y ago
What about bounds checking and stuff? Sorry for my ignorance on the matter.
- Jtsummers 12y agoIt seems you can use unsafe versions of vectors/arrays/strings to bypass bounds checking. Essentially, if you're very confident that your code is correct, then you can speed it up (is it worth it?) to C levels. On the other hand, a lot of bounds checking is probably going to happen where you'd manually enter it into C/C++ code anyways (if you wanted to avoid certain errors).
- portmanteaufu 12y agoAdditionally, idiomatic Rust code will employ iterators rather than direct indexing where possible. Rust's iterators are memory safe and do not perform bounds checking.
- DCKing 12y agoIt appears the compiler optimizes out bounds checking if and only if it can tell during compile time that the index is correct [1]. Arrays of dynamic size or with dynamic references are bound checked. In dynamic cases you should be writing manual bound checking guards in C anyway. [1]: https://github.com/mozilla/rust/issues/9024 https://github.com/mozilla/rust/issues/9024
- pcwalton 12y agoNot only do iterators help avoid them in most cases, I'm anxiously awaiting Intel MPX for more hardware support for bounds checks.