   How could I optimize this code?
void Byteswapping(unsigned char* aDest, unsigned char* aSource, int size){  int i, j;  int iTimesSize;  for (i=0; i<size; i++)  {    iTimesSize = i * size;    for (j = 0; j<size; j++)    { aDest[iTimesSize+j]=aSource[j*size+i];    }  }}Is there a easy way to optimize this?   
void Byteswapping(unsigned char* aDest, unsigned char* aSource, int size){  aDest = aSource;}Whould this mean the same?   ;  Looks relatively optimized to me, short of doing assembly level stuff. Possibly use the restrict keyword on the char * parameters.   ;Quote:Original post by darkforestvoid Byteswapping(unsigned char* aDest, unsigned char* aSource, int size){  aDest = aSource;}Whould this mean the same?Nope.It only changes the local value of aDest.Perhaps memcpy, or std::swap if you are using c++?   ;Quote:Original post by darkforestIs there a easy way to optimize this?Not that I can see. Your compiler probably already does strength reduction and loop unrolling for you.   ;Quote:Perhaps memcpy, or std::swap if you are using c++?for (i=0; i<   ;Quote:Perhaps memcpy, or std::swap if you are using c++?for (i=0; i<;  What is the goal of your function?  I'm messing around with it, and it's not really copying a C string correctly...  Are you trying to flip bytes in memory, so that a C string would be spelled backwards?   ;  erm third time luckyNormally pre increment is faster than post increment.(machine dependent optimization)   ;  He'd have to flip his code around, it'd work more like this then:void Byteswapping(unsigned char* aDest, unsigned char* aSource, int size){  int i, j;  int iTimesSize;  i = 0;  while(i<size)  {    iTimesSize = i * size;    j = 0;    while(j<size)    { aDest[iTimesSize+j]=aSource[j*size+i]; ++j;    }  ++i;  }}Besides, I have a feeling that leaving it as a for loop would be faster due to automatic compiler optimizations.   