Does unaligned memory access always cause bus errors?

后端 未结 3 1662
予麋鹿
予麋鹿 2020-11-28 13:39

According to the Wikipedia page Segmentation fault, a bus error can be caused by unaligned memory access. The article gives an example about how to trigger a bus er

3条回答
  •  萌比男神i
    2020-11-28 14:19

    1. It may be significantly slower to access unaligned memory (as in, several times slower).

    2. Not all platforms even support unaligned access - x86 and x64 do, but ia64 (Itanium) does not, for example.

    3. A compiler can emulate unaligned access (VC++ does that for pointers declared as __unaligned on ia64, for example) - by inserting additional checks to detect the unaligned case, and loading/storing parts of the object that straddle the alignment boundary separately. That is even slower than unaligned access on platforms which natively support it, however.

提交回复
热议问题