内存对齐目的目的、内存

2023-09-11 23:32:14 作者:我可以原谅所有事,原谅所有人,但我不能原谅自己以前所付出的真

诚然,我不明白这一点。假设你有1个字节长度的记忆单词记忆。为什么你不能访问一个4字节长的变量在未对齐地址(即不被4整除)一个内存访问,因为它与对齐地址的情况?

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 unaligned address(i.e. not divisible by 4), as it's the case with aligned addresses?

推荐答案

这是许多底层处理器的限制。它通常可以做4低效的单字节进行合作周围取而不是一个有效的字获取,但是很多语言说明符决定了它会更容易只取缔他们,并强制所有内容保持一致。

It's a limitation of many underlying processors. It can usually be worked around by doing 4 inefficient single byte fetches rather than one efficient word fetch, but many language specifiers decided it would be easier just to outlaw them and force everything to be aligned.

还有更多信息,此链接中的OP发现的。

There is much more information in this link that the OP discovered.

 
精彩推荐