Re: TextOut() to a DialogBox ???
Peter Olcott wrote:
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];
Divide and conquer! 99.9999999999999999% (ok, 99.0567%) of the time,
a GPF (General Protection Fault) is because you are basically
referencing protected memory that doesn't belong to you. This is
part of the reason for virtualization - to manage the memory
references to help protect against buggy applications killing others.
The reference or pointer could be due to miscalculation or corruption
called Buffer Overflow or UnderFlow or just plain Clobbering.
This is a buffer overflow:
char peter[10]; // 9 bytes + null
char hector[10]; // 9 bytes + null
// off by one, one byte flows over to hector.
strcpy(peter,"1234567890");
Buffer overflow is the typical error with most bugs, and the one
hackers try to create in the stack.
Buffer underflow is the opposite, maybe by miscalculating a pointer:
strcpy(hector - 2, "1234567890")
These are harder to see because you underflowing hector by putting two
bytes at the end of peter. Peter still has a length of zero because
the first byte is NULL.
In any case, a GPF is about accessing memory that does not belong to
you. It is protected memory, hence the term General Protection Fault.
--
HLS