Why does CPU access memory on a word boundary?

后端 未结 4 700
情话喂你
情话喂你 2020-12-24 02:34

I heard a lot that data should be properly aligned in memory for better access efficiency. CPU access memory on a word boundary.

So in the following scenario, the C

4条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-24 03:13

    Because it is more efficient.

    In your example, the CPU would have to do two reads: it has to read in the first half, then read in the second half separately, then reassemble them together to do the computation. This is much more complicated and slower than doing the read in one go if the data was properly aligned.

    Some processors, like x86, can tolerate misaligned data access (so you would still need all 32 bits) - others like Itanium absolutely cannot handle misaligned data accesses and will complain quite spectacularly.

提交回复
热议问题