Gordon Pearce wrote: > > > > > 2 possible implementations of this are: > > > > [deletia] > > > > > The first solution will be faster but the algorithm hasn't changed. It's > > Why will it be faster? Is it something to do with the way the array is > referenced?
Sorry everyone, Paul started it by talking about ptr++ :). I'll talk about a 3x3 array rather than a 10x10 to save on typing/reading. In C, a 3x3 array would be stored in memory as: array[0,0]:array[0,1]:array[0,2]:array[1,0]:array[1,1]:array[1,2]:array[2,0]:array[2,1]:array[2,2] For the first implementation, you see that we would reference the memory in the following order: [0,0]:[0,1]:[0,2]:[1,0]:[1,1]:[1,2]:[2,0]:[2,1]:[2,2]. This is the same order as which it is stored in memory. For the second we would reference the memory in the folling order: [0,0]:[1,0]:[2,0]:[0,1]:[1,1]:[2,1]:[0,2]:[1,2]:[2,2]. Which will just have the computer jumping around it's memory locations. (Which isn't good!) For those of you who care, in fortran, it's the exact opposite. Thanks, Allan -- Where in the nursery rhyme does it say Humpty Dumpty is an egg? -------------------------------------------------------------------- http://www.lug.org.uk http://www.linuxportal.co.uk http://www.linuxjob.co.uk http://www.linuxshop.co.uk --------------------------------------------------------------------
