沿着4字节边界对齐 [英] Alignment along 4-byte boundaries

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

问题描述

最近我在思考对齐......这件事情,我们通常不具备的考虑,但我已经意识到有些处理器要求的对象以及4字节边界对齐。究竟这是否意味着,和哪些特定的系统有对齐要求?

I recently got thinking about alignment... It's something that we don't ordinarily have to consider, but I've realized that some processors require objects to be aligned along 4-byte boundaries. What exactly does this mean, and which specific systems have alignment requirements?

假设我有一个任意的指针:

Suppose I have an arbitrary pointer:

无符号字符* PTR

现在,我尝试从一个存储单元中的双重价值:

Now, I'm trying to retrieve a double value from a memory location:

双D = **((双*)PTR);

难道这会导致问题?

推荐答案

这肯定会产生一些系统上的问题。

It can definitely cause problems on some systems.

例如,在基于ARM的系统不能处理未对齐一个4字节边界的32位的字。这样做会导致访问冲突异常。在x86上,您可以访问这种非对齐的数据,尽管性能会受到影响,因为两个词一点都取从内存中,而不是只有一个。

For example, on ARM-based systems you cannot address a 32-bit word that is not aligned to a 4-byte boundary. Doing so will result in an access violation exception. On x86 you can access such non-aligned data, though the performance suffers a little since two words have to fetched from memory instead of just one.

这篇关于沿着4字节边界对齐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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