Click here to Skip to main content
16,008,010 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: clickable bitmap colour problems Pin
Mike Dimmick27-Nov-03 9:26
Mike Dimmick27-Nov-03 9:26 
GeneralCFileDialog - Reset the last configuration Pin
Denislef27-Nov-03 5:55
Denislef27-Nov-03 5:55 
GeneralActiveX Problem Pin
Java2C#27-Nov-03 5:14
Java2C#27-Nov-03 5:14 
QuestionMost optimized way to reverse a string? Pin
melwyn27-Nov-03 4:38
melwyn27-Nov-03 4:38 
AnswerRe: Most optimized way to reverse a string? Pin
Anonymous27-Nov-03 5:13
Anonymous27-Nov-03 5:13 
GeneralRe: Most optimized way to reverse a string? Pin
melwyn27-Nov-03 5:24
melwyn27-Nov-03 5:24 
AnswerRe: Most optimized way to reverse a string? Pin
Ian Darling27-Nov-03 5:37
Ian Darling27-Nov-03 5:37 
AnswerRe: Most optimized way to reverse a string? Pin
Mike Dimmick27-Nov-03 6:23
Mike Dimmick27-Nov-03 6:23 
So, what's wrong with std::reverse? The compiler's supplied library is usually pretty well optimised for the task in hand.

In the general case, forget about trying to eliminate variables, loops etc in your code. The compiler can do that when it optimises - unrolling loops, enregistering variables, removing common terms.

Compile your code in release mode for a simple implementation, then see what the compiler did with it. Shortest C++ code is not necessarily shortest or fastest object code.

So, the best optimised code is probably
void ReverseString( char* sz, size_t len )
{
   char ch;
 
   for ( size_t idx = 0; idx < len / 2; ++idx )
   {
      ch = sz[idx];
      sz[idx] = sz[len - idx - 1];
      sz[len - idx - 1] = ch;
   }
}
The compiler hoists the division of len by 2 out of the loop (and also converts it to a right-shift by 1). It also converts the sz[len - idx - 1] terms into a pointer and moves it back down from the end.

Finally, it uses the dl register (the least significant byte of edx to store ch, which is never stored to main memory.

Stick to simple code.
GeneralRe: Most optimized way to reverse a string? Pin
Obliterator27-Nov-03 6:39
Obliterator27-Nov-03 6:39 
GeneralRe: Most optimized way to reverse a string? Pin
melwyn28-Nov-03 0:08
melwyn28-Nov-03 0:08 
AnswerRe: Most optimized way to reverse a string? Pin
фил4-Dec-03 21:57
фил4-Dec-03 21:57 
GeneralRe: Most optimized way to reverse a string? Pin
melwyn7-Dec-03 20:08
melwyn7-Dec-03 20:08 
Questionwitch message? Pin
willempipi27-Nov-03 4:33
willempipi27-Nov-03 4:33 
AnswerRe: witch message? Pin
Johnny ²27-Nov-03 4:54
Johnny ²27-Nov-03 4:54 
GeneralRe: witch message? Pin
willempipi27-Nov-03 5:45
willempipi27-Nov-03 5:45 
GeneralRe: witch message? Pin
Ravi Bhavnani27-Nov-03 6:58
professionalRavi Bhavnani27-Nov-03 6:58 
GeneralRe: witch message? Pin
melwyn27-Nov-03 20:21
melwyn27-Nov-03 20:21 
GeneralDLL Help Pin
Obliterator27-Nov-03 3:59
Obliterator27-Nov-03 3:59 
GeneralRe: DLL Help Pin
melwyn27-Nov-03 4:20
melwyn27-Nov-03 4:20 
GeneralRe: DLL Help Pin
Obliterator27-Nov-03 4:57
Obliterator27-Nov-03 4:57 
GeneralRe: DLL Help Pin
Mike Dimmick27-Nov-03 6:30
Mike Dimmick27-Nov-03 6:30 
GeneralRe: DLL Help Pin
Obliterator27-Nov-03 6:36
Obliterator27-Nov-03 6:36 
GeneralRe: DLL Help Pin
melwyn27-Nov-03 23:30
melwyn27-Nov-03 23:30 
GeneralRe: DLL Help Pin
Obliterator28-Nov-03 3:03
Obliterator28-Nov-03 3:03 
QuestionHow to set the &quot;Dialog Focus&quot; in Dialog Based Application Pin
eshban28427-Nov-03 3:42
eshban28427-Nov-03 3:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.