|
From: Daniel K. O. <dan...@ya...> - 2003-08-04 21:52:20
|
OROSZI Balázs wrote:
> So actually, the whole stuff is stored linearly, and the compiler
> deals with multiplication, to get the final address in memory,
> relative to prop.
>
> And another question arose in me, reading the above: multiplication.
> Isn't that slow? I mean, if I use a loop, and I do a lot of indexing,
> that results in a lot of multiplication, no? Wouldn't it be better
> then to just incerement the pointer itself. Like, instead of this:
>
> int i,array[100];
> for(i=0;i<100;++i){
> DoSomething(array[i]);
> }
>
> do this:
>
> int *i,array[100];
> for(i=array;i<array+100;++i){
> DoSomething(*i);
> }
>
> Would it be faster?
With a good compiler, both of them should be identical. The question
"which is faster" you can test yourself, using clock() before and after
the calls, and see what you get.
Daniel K. O.
|