Mail Archives: djgpp/1996/11/28/04:41:13
Glen Miner wrote:
[...]
> How well will djgpp deal with two dimentional arrays? Say I'm stepping
> through char MyArray[9][9] like so:
>
> for (x = 0; x < 6; x++)
> for (y = 0; y < 7; y++)
> MyArray [x][y] = SomeValue;
>
> Will it be smart and index it by a pointer so that it doesn't have to
> recalculate the address every time?
>
This can be done faster if you say
for(x=6; x; --x)
for(y=7 ; y; --y)
MyArray[x][y] = SomeValue;
because instead of comparing to a memory value (6 and 7), simply
checking for the Zero flag suffices.
Even better is probably
for(x=6, foo= MyArray; x; --x)
for(y=7 ; y; --y)
*foo++ = SomeValue;
thus preserving the direction you fill the stuff.
This example doesn't work in your case, as you are not filling
the entire array, but only parts. So you need some extra computations
within the for(...) to get foo pointing to the right
array cell.
Also, depending on your processor, the data, the weather and such,
-O2 sometimes yields better performance, because a loop fits
inside the cache, instead of being elegantly unrolled but
punished with memory access.
--
Ciao
Tom
*************************************************************
* Thomas Demmer *
* Lehrstuhl fuer Stroemungsmechanik *
* Ruhr-Uni-Bochum *
* Universitaetsstr. 150 *
* D-44780 Bochum *
* Tel: +49 234 700 6434 *
* Fax: +49 234 709 4162 *
* Voice/Fax Box: +49 2561 91371 2056 *
* http://www.lstm.ruhr-uni-bochum.de/~demmer *
*************************************************************
- Raw text -