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

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

问题描述

诚然,我不明白这一点。假设你有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天全站免登陆