内存对齐的目的 [英] Purpose of memory alignment

查看:26
本文介绍了内存对齐的目的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

诚然,我不明白.假设您有一个长度为 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.

这篇关于内存对齐的目的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆