From: Thomas Demmer Newsgroups: comp.os.msdos.djgpp Subject: Re: Optimization Date: Thu, 28 Nov 1996 09:05:48 +0100 Organization: Lehrstuhl fuer Stroemungsmechanik Lines: 52 Message-ID: <329D47DB.41C6@LSTM.Ruhr-UNI-Bochum.De> References: NNTP-Posting-Host: bvb.lstm.ruhr-uni-bochum.de Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp 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 * *************************************************************