Re: No boundschecking?
On Jan 30, 1:29 am, Ian Collins <ian-n...@hotmail.com> wrote:
mike3 wrote:
On Jan 30, 12:56 am, Jerry Coffin <jcof...@taeus.com> wrote:
In article <51bd62d8-0fa5-4fad-9d3c-
6502e6525...@e23g2000prf.googlegroups.com>, mike4...@yahoo.com says...
[ ... ]
But what about if I want to disable the bounds-checking for
performance purposes, and enable it for debug purposes? That's what
I want: boundschecking I can turn on and off.
It's not as pretty as anybody would like, but one easy way is to use
your own preprocessor-dependent definitions, something like:
class RawDigit {
std::vector<Digit> digits;
#ifdef DEBUG
Digit &operator[](std::size_t index) {
return digits.at(index);
}
Digit Operator[](std::size_t index) const {
return digits.at(index);
}
#else
Digit &operator[](std::size_t index) {
return digits[index];
}
Digit operator[](std::size_t index) const {
return digits[index];
}
#endif
The rest of your code uses these instead of using the vector directly.
Hmm. This might work, however won't the calling
overhead to the operator[] be an issue? (I take
it you can't just tell the compiler to inline these.)
I'll have to bench it and see how fast it goes.
You don't have to tell the compiler, it will (or at least should!)
inline such trivial methods.
So if my compiler doesn't inline that, then that
doesn't indicate poor code, it indicates a poor
compiler, which I should throw out and substitute
a better one for, right?
Obviously, looking at this there are no "perfect"
solutions (not a surprise, though.). This therefore
raises the question of whether any of the solutions
here are adequate for the purposes at hand.
The whole point of the routines I've been struggling
so hard to craft here was to try and minimize the
bug-susceptibility of my code, but I also need high
performance. Therefore, the question comes up of
what the best way is to code these core routines,
like the adder I posted. What is it?