StoneColdCrazy
Programmer
I am poor at implemention efficient algorithms, I can write almost anything, but that anything isn't always fast enough. <br><br>Can someone help me to understand how to make things faster?<br><br>Here is a flipping-the-image algorithms I wrote a year ago, don't use it anymore, so I won't benifit from improved version. It's C++, but most of C guys today know C++ well.<br><br>// typedef unsigned char BYTE;<br>// typedef unsigned short int WORD;<br><br>// class TBitmap<br>// {<br>// WORD width;<br>// WORD height;<br>// BYTE *data; // data eventually newed to<br>// }; // data[width*height]<br><br>//---------------------------------------------------------<br>void TBitmap::FlipHorizontal()<br> {<br> WORD mid = width/2;<br> WORD offset = 0;<br> BYTE temp;<br><br> for(WORD i=0, x; i<height; ++i)<br> {<br> for(x=0; x<=mid; ++x)<br> {<br> temp = data[offset+x];<br> data[offset+x] = data[offset+width-x];<br> data[offset+width-x] = temp;<br> }<br><br> offset += width;<br> } <br> }<br><br><br>the 486 assembly code produced for this function is almost 1 page long, there have to be a shorter and faster way..<br><br>~al<br><br><br>