Purpose of memory alignment

前端 未结 8 1298
伪装坚强ぢ
伪装坚强ぢ 2020-11-22 05:20

Admittedly I don\'t get it. Say you have a memory with a memory word of length of 1 byte. Why can\'t you access a 4 byte long variable in a single memory access on an unalig

8条回答
  •  有刺的猬
    2020-11-22 05:41

    @joshperry has given an excellent answer to this question. In addition to his answer, I have some numbers that show graphically the effects which were described, especially the 2X amplification. Here's a link to a Google spreadsheet showing what the effect of different word alignments look like. In addition here's a link to a Github gist with the code for the test. The test code is adapted from the article written by Jonathan Rentzsch which @joshperry referenced. The tests were run on a Macbook Pro with a quad-core 2.8 GHz Intel Core i7 64-bit processor and 16GB of RAM.

提交回复
热议问题