|
From: Ioannis V. <iv...@em...> - 2003-08-04 22:55:54
|
> -----Original Message-----
> From: dev...@li...
> [mailto:dev...@li...] On Behalf
> Of OROSZI Balazs
> Sent: Tuesday, August 05, 2003 12:10 AM
> To: dev...@li...
> Subject: Re: [Dev-C++] arrays in structures
>
> >
> > M$ says Yes.
> >
> > From MSDN:
> >
> > -- cut here --
> > int prop[3][4][6];
> > ...
> > i = prop[2][1][3];
So what?
> 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?
No, because the compiler undestands indexing as pointer
addition/subtraction.
So your indxing code above is perceived by the compiler as:
int i,array[100];
for(i=0;i<100;++i){
DoSomething(*(array+i));
}
Ioannis Vranos
* Programming pages: http://www.noicys.freeurl.com
* Alternative URL 1: http://run.to/noicys
* Alternative URL 2: http://www.noicys.cjb.net
|