Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Coding for Performance: Data alignment and structures (2013) (intel.com)
49 points by bluetomcat on Oct 28, 2014 | hide | past | favorite | 3 comments


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...

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...


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


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.




Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: