Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I tested this some time in the past on Win32 machines and did not notice much of a penalty on 32-bit machines. On 64-bit, though, it was significantly slower. For example, I ran the following bit of code. On a 32-bit machine, the times printed were hardly changed. But on a 64-bit machine, the times for the misaligned accesses were nearly twice as long. The times follow the code.</p> <pre><code>#define UINT unsigned __int64 #define ENDPART QuadPart #else #define UINT unsigned int #define ENDPART LowPart #endif int main(int argc, char *argv[]) { LARGE_INTEGER startCount, endCount, freq; int i; int offset; int iters = atoi(argv[1]); char *p = (char*)malloc(16); double *d; for ( offset = 0; offset &lt; 9; offset++ ) { d = (double*)( p + offset ); printf( "Address alignment = %u\n", (unsigned int)d % 8 ); *d = 0; QueryPerformanceFrequency(&amp;freq); QueryPerformanceCounter(&amp;startCount); for(i = 0; i &lt; iters; ++i) *d = *d + 1.234; QueryPerformanceCounter(&amp;endCount); printf( "Time: %lf\n", (double)(endCount.ENDPART-startCount.ENDPART)/freq.ENDPART ); } } </code></pre> <p>Here are the results on a 64-bit machine. I compiled the code as a 32-bit application.</p> <pre><code>[P:\t]pointeralignment.exe 100000000 Address alignment = 0 Time: 0.484156 Address alignment = 1 Time: 0.861444 Address alignment = 2 Time: 0.859656 Address alignment = 3 Time: 0.861639 Address alignment = 4 Time: 0.860234 Address alignment = 5 Time: 0.861539 Address alignment = 6 Time: 0.860555 Address alignment = 7 Time: 0.859800 Address alignment = 0 Time: 0.484898 </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload