void swapBufferChunks( U8 *buf, U32 start1, U32 start2, U32 bufsize ) { register U64 *p1 = (U64*)&buf[ start1 ]; register U64 *p2 = (U64*)&buf[ start2 ]; register U64 temp; shift_size = p2 - p1; end_buf = p1 + bufsize; # assuming bufsize is byte count item_count = bufsize / 8; # assuming elements are 8-bytes each iter_count = 0; bgn_ofs = p1; temp = *p1; while ( iter_count < item_count ) { if ( p2 = bgn_ofs ) { *p1 = temp; iter_count++; last if ( iter_count == item_count ); # break out of while loop as soon as this is true p1++; p2++; bgn_ofs = p1; temp = *p1; } *p1 = *p2; iter_count++; p1 = p2; p2 += shift_size; p2 -= bufsize if ( p2 >= end_buf ); } }