Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Arrays and Pointers...

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hi! i would really like to ask you all if there is any difference in speed and performance in using pointers instead of array ( the blabla[x] ). Is there any performance gain in using pointers more than arrays? If so, why is that? Thank you very much in advance...
 
It's the same; foo[x] is translated by the compiler to *(foo+x).
 
There used to be a huge difference between:
p= blabal ; p ++ ;
and
blabla[x ++]

Back in the dark ages, the difference in runtime for a screen grabbing loop was:
arrays 170 seconds
pointers 10 seconds

Now adays, there's so much [] use out there the compiler
writers made it much more competative. (And once in a
while the [] is faster if you're too clever with pointers.)

When in doubt however, benchmark it.

In the dark dark ages, it was even faster to count down in a for loop than it was to count up and compare. You might once in a while see an old:
for (i= 100; (i --); ) ...
which saved a few instructions on a 68030 vs
for (i= 0; (i < 100); i ++) ...

Don't do it anymore though. VC produces worse code for the count down than it does for the count up. Actually, the horrifying thing is that the un-optimized count down is the fastest; but the optimized count down is slower than either version of the count up. Somebody in the optimization group really had their head in a blender.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top