

Coding for Performance: Data alignment and structures (2013) - bluetomcat
https://software.intel.com/en-us/articles/coding-for-performance-data-alignment-and-structures

======
userbinator
Note that in modern x86 processors the overhead of unaligned accesses is
nearly 0 - caching has more significant effect, so it's more important to make
sure frequently accessed data can fit within a cache line even if it means
some of it won't be aligned. Crossing cache-line boundaries is when things
slow down.

[http://lemire.me/blog/archives/2012/05/31/data-alignment-
for...](http://lemire.me/blog/archives/2012/05/31/data-alignment-for-speed-
myth-or-reality/)

Edit: here's an algorithm that exploits this "nearly free" unaligned access
for fast substring search:
[http://www.codeproject.com/Articles/250566/Fastest-strstr-
li...](http://www.codeproject.com/Articles/250566/Fastest-strstr-like-
function-in-C)

------
srcmap
In the rearrange example, can/does the compiler do the rearrange, padding
automatically?

~~~
CJefferson
In both C and C++ fields in structs must be outputted in the order they are
listed.

There is in C++ a freedom to rearrange fields whenever the user switches
between public/private/protected, but I believe no compiler takes advantage of
it, because (I believe) it is believed too suprising for these kinds of
changes to change a class' size.

