双定位 [英] Double alignment

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

问题描述

这个帖子,我已经明白,主要原因讨论结构成员的对齐是性能(和一些架构限制)。

Following the discussion from this post, I have understood that the main reason for the alignment of structure members is performance (and some architectures restrictions).

如果我们将调查微软(的Visual C ++),Borland公司/ codeGear - 编译为32位x86时(C ++ Builder中),数字火星(DMC)和GNU(GCC):用于比对的 INT 4个字节,如果 INT 未对齐,它可能发生2行内存的银行将被读取。

If we will investigate Microsoft (Visual C++), Borland/CodeGear (C++-Builder), Digital Mars (DMC) and GNU (GCC) when compiling for 32-bit x86: The alignment for int is 4 bytes and if int is not aligned, it can happen that 2 rows of memory banks will be read.

我的问题是,为什么不作双击将4个字节对齐也? 4个字节对齐双击也将导致2行存储体读....

My question is why not to make double to be 4 bytes aligned also? 4 bytes aligned double also will cause 2 rows of memory banks reading....

例如在下面的例子中,由于双击 8对齐,结构的实际大小将的sizeof(字符)+(调整双填充)+的sizeof(INT)= 20字节

For example in the following example, since double is 8-aligned, the actual size of structure will be sizeof(char) + (alignment for double padding) + sizeof(int) = 20 bytes.

typedef struct structc_tag{
    char        c;
    double      d;
    int         s;
} structc_t;

感谢您

推荐答案

这是扩展的评论:

据了解GCC文档 -malign双

对齐双重双字边界上变量产生,在更多的内存为代价稍快于奔腾运行code。

Aligning double variables on a two-word boundary produces code that runs somewhat faster on a Pentium at the expense of more memory.

在x86-64的,默认情况下启用 -malign双

On x86-64, -malign-double is enabled by default.

警告:如果您使用 -malign双开关,包含上述类型的结构比发布的应用程序二进制接口规格为386排列不同,是不是二进制在$ C $结构相容ç编译没有这种开关。

Warning: if you use the -malign-double switch, structures containing the above types are aligned differently than the published application binary interface specifications for the 386 and are not binary compatible with structures in code compiled without that switch.

一个字在这里的意思I386字是32位。

A word here means i386 word which is 32 bits.

Windows使用 64位对齐即使是在32位模式下的双值,而SysV的i386的ABI一致性Unix一样使用32位对齐。 32位Windows API,Win32中,来自从Windows NT 3.1,它不同于当前一代的Windows版本中,英特尔的目标386,阿尔法,MIPS甚至晦涩英特尔的i860。像Alpha和MIPS本地RISC系统要求双击值是64位对齐(否则硬件故障发生时),便携性可能是在64位对齐背后的理由在Win32的i386 ABI。

Windows uses 64-bit alignment of double values even in 32-bit mode, while SysV i386 ABI conformant Unices use 32-bit alignment. The 32-bit Windows API, Win32, comes from Windows NT 3.1, which, unlike current generation Windows versions, targeted Intel i386, Alpha, MIPS and even the obscure Intel i860. As native RISC systems like Alpha and MIPS require double values to be 64-bit aligned (otherwise hardware fault occurs), portability might have been the rationale behind the 64-bit alignment in the Win32 i386 ABI.

64位x86系统,也称为AMD64或x86-64的,或x64,需要双击值是64位的,否则对齐的错位故障发生和硬件确实昂贵的固定式,这considreably减慢内存访问。这就是为什么双击值是64位的所有现代的x86-64的ABI(SysV的和Win32)。对齐

64-bit x86 systems, know also as AMD64 or x86-64, or x64, require double values to be 64-bit aligned otherwise a misalignment fault occurs and the hardware does an expensive "fix-up" which considreably slows down memory access. That's why double values are 64-bit aligned in all modern x86-64 ABIs (SysV and Win32).

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

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