In message <>, Lars Uffmann
<> writes
>peter koch wrote:
>> This is because you do not use std::vector. Always use high-level
>> constructs unless you have a good reason not to: low level programming
>> requires you to take care of lots of details that are irrelevant to
>> your problem and might be difficult to get right.
>
>I fail to see a problem other than getting the size right in this
>case... Isn't speed always a "good reason" to do low level programming?
Not if it conflicts with clarity and maintainability. Less still when
it's probably fictional (it's unlikely that initialising a vector of
ints takes any longer than using new[] and memset.)
In any case, first you'd have to show (a) that the high-level solution
is too slow, (b) the low-level solution is actually faster, and (c) that
the speed increase actually has a measurable effect on the performance
of the program as a whole.
>I am somewhat estranged here by your general "always use high-level
>constructs" statement.
>
>> One of your problems here is that sizeof did not return what you
>> thought, but there are other problems lurking!
>
>Care to enlighten me, for one?
I'm curious. Assuming he has set n to
>4 first
and should synchronize n with the max value for j, and
>should probably link the size of the array construction to that with a
>const/variable,
That's three assumptions already
>I currently see no other problems...
Until he decides to switch from int to some user-defined type that isn't
POD...
--
Richard Herring