"Peter Olcott" <NoSpam@OCR4Screen.com> wrote in message
news:0YmdnXNrsfoxMjfWnZ2dnUVZ_oadnZ2d@giganews.com...
"Geoff" <geoff@invalid.invalid> wrote in message
news:qf5lq556kt4oh22dq12c73sp161ogbgqgr@4ax.com...
On Wed, 24 Mar 2010 15:39:26 -0500, "Peter Olcott"
<NoSpam@OCR4Screen.com> wrote:
Here is an interesting note that I don't understand. A
slight revision (to make it a little less CPU intensive,
thus more memory intensive) only actually achieves 21 MB
per second
of the 12 GB / second maximum RAM speed.
(RAM speed reported by MemTest86).
const uint32 size = 100000000;
std::vector<uint32> Data;
uint32 Max = 0x3fffffff;
void Process() {
clock_t finish;
clock_t start = clock();
double duration;
uint32 num;
for (uint32 N = 0; N < Max; N++)
num = Data[num];
finish = clock();
duration = (double)(finish - start) / CLOCKS_PER_SEC;
printf("%4.2f Seconds\n", duration);
}
Another thing that I don't understand is that it crashes
when
num = Data[num];
is replaced by
num = Data[N];
Two bugs exist.
1. You never initialize num [...]
Right
Which gives a C4700 compiler warning, btw. Assuming you
somehow
overlooked, or chose to ignore that, the debugger would
have stopped
on the offending line with all the necessary clues to
figure out why.
You _did_ run it under the debugger before asking for help
on usenet
and waiting many hours to learn the all too obvious
answer... right?
2. You never resize the vector space "Data" before you
attempt to
access it.
Data.resize(Max);
Wrong. (reserve() has almost the same effect as
resize() )
int main() [...]
Geoff was replying to your earlier post, which showed no
'reserve'.
You only included the main() part and 'reserve' in the
later followup.
Liviu
I had the whole thing posted yesterday. An error of false