----- Original Message -----
From: Richard A. Smith <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Friday, October 15, 1999 12:10 AM
Subject: Re: [MP3 ENCODER] toolame 01d (fwd)


> On Fri, 15 Oct 1999 00:47:38 +0900, Takehiro Tominaga wrote:
>
> >
> >Because on my architecture, (intel celeron 464MHz + gcc2.95.1), arrays
> >are more efficient than lots of pointers. I think most currently
>
> Do you have any pointers to info on why this is the case?  What
> exactly do you mean by more efficient?

I think arrays can be more efficient because they help the compiler rule out
aliasing - array1[m] and array2[n] can never refer to the same data, but *p1
and *p2 might. (FORTRAN has a more restricted definition of pointers than C,
and as a result can sometimes be more efficient).

In general, I don't use pointers instead of arrays unless
1) doing so would make the algorithm clearer
or
2) it would allow me to exploit some non-obvious property of the data and
its layout - "obvious" being defined by the compiler. :)
AND
3) profiling shows it to be faster
AND
4) (of course) it matters that it be faster :)

With modern compilers, you don't generally need to bother with replacing

  for (i = 0; i < len; ++i)
    sum += array[i];

with

  for (p = array, endp = array + len; p < endp; ++p)
    sum += *p;

Any compiler worth its salt will do it for you in a microsecond - or might
not, if it thinks it will be less efficient; performing the strength
reduction yourself restricts the compiler's options.

-- Mat.


--
MP3 ENCODER mailing list ( http://geek.rcc.se/mp3encoder/ )

Reply via email to