Re: mu TECH: an unhurried digression on C pointers vs. arrays

From: Alfie Costa (agcosta@gis.net)
Date: Wed May 03 2000 - 22:04:07 CEST


On 28 Apr 2000, at 17:58, Miguel Angel <mulinux@sunsite.auc.dk> wrote:

> To notice such subtle difference (if there is any at all) is better to write the
> loop repeating many times the inner sentences (unless you are also testing the
> loop).

OK, I have tried this. I defined the code like so:

#define C1 line[j]=z;n=line[j];j++;line[j]=y;n=line[j];j--;
#define C2 *l=z;n=*l++;*l=y;n=*l--;

...then inserted about about 150 'C1's and 'C2's in each loop. The result was
that the loop with the pointers really did turn out to be faster, around 30-50%
if I recall correctly -- whatever the exact figure was, the pointers were
always faster. The code was tested with 'gcc', I haven't tried that old Turbo C
compiler yet.
 
Naturally this was a surprise, given the previous confusing results which used
much more loop overhead. Thanks again for suggesting this.

If anyone wants the code, I'll e-mail it on request...

---------------------------------------------------------------------
To unsubscribe, e-mail: mulinux-unsubscribe@sunsite.auc.dk
For additional commands, e-mail: mulinux-help@sunsite.auc.dk



This archive was generated by hypermail 2.1.6 : Sat Feb 08 2003 - 15:27:14 CET