“立即打包以强制记录的字节对齐”是什么?意思? [英] What does "Packed Now Forces Byte Alignment of Records" mean?

查看:89
本文介绍了“立即打包以强制记录的字节对齐”是什么?意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Delphi XE2的新增功能包含后续

The What's New for Delphi XE2 contains the following.


打包现在强制记录的字节对齐



如果您有使用打包记录的遗留代码类型,并且您希望
与外部DLL或C ++链接,则需要从代码中删除打包一词
。现在,packed关键字强制字节对齐
,而过去并不一定要这样做。行为
的更改与Del​​phi
2009中的C ++对齐兼容性更改有关。

Packed Now Forces Byte Alignment of Records

If you have legacy code that uses the packed record type and you want to link with an external DLL or with C++, you need to remove the word "packed" from your code. The packed keyword now forces byte alignment, whereas in the past it did not necessarily do this. The behavior change is related to C++ alignment compatibility changes in Delphi 2009.

我不明白这个。我在这一点上苦苦挣扎:在过去,不一定要这么做。我无法调和的是,据我所知,压缩总是导致记录的字节对齐。谁能举一个不按字节对齐的打包记录的例子吗?显然,这必须是较早的版本。

I don't understand this. I'm struggling with this point: whereas in the past it did not necessarily do this. What I cannot reconcile is that packed has always resulted in byte alignment of records to the best of my knowledge. Can anyone give an example of a packed record that is not byte aligned? Obviously this would have to be in an earlier version.

文档为什么会说如果要与外部DLL或C ++链接,则需要删除您的代码中包含的单词?如果外部代码使用 #pragma pack(1),那么如果打包超出限制怎么办?

Why do the docs say "if you want to link with an external DLL or with C++, you need to remove the the word packed from your code"? If the external code uses #pragma pack(1) then what are we to do if packed is off limits?

$ ALIGN 指令怎么样?是 {$ A1}和{$ A-} 等于打包的,还是<$ c有其他含义? $ c> packed ?

What about the $ALIGN directive? Are {$A1} and {$A-} equivalent to packed or is there some extra meaning with packed?

似乎我丢失了一些东西,如果有人可以解释一下,我将不胜感激。还是文档真的很差?

It seems that I'm missing something and would appreciate it if somebody could explain this. Or is the documentation just really poor?

更新

我很合理确信文档是指记录本身的 alignment 而不是记录的 layout 。这是一个小程序,它显示在记录上使用压缩的会强制将记录的对齐方式设置为1。

I'm reasonably convinced that the documentation is referring to alignment of the record itself rather than the layout of the record. Here's a little program that shows that the the use of packed on a record forces the alignment of the record to be 1.

program PackedRecords;
{$APPTYPE CONSOLE}
type
  TPackedRecord = packed record
    I: Int64;
  end;

  TPackedContainer = record
    B: Byte;
    R: TPackedRecord;
  end;

  TRecord = record
    I: Int64;
  end;

  TContainer = record
    B: Byte;
    R: TRecord;
  end;

var
  pc: TPackedContainer;
  c: TContainer;

begin
  Writeln(NativeInt(@pc.R)-NativeInt(@pc.B));//outputs 1
  Writeln(NativeInt(@c.R)-NativeInt(@c.B));//outputs 8
  Readln;
end.

在Delphi 6、2010,XE和XE2 32位和XE 64位上产生相同的输出。

This produces the same output on Delphi 6, 2010, XE and XE2 32 bit and XE 64 bit.

推荐答案

文档的最新更新已删除该问题所基于的所有文本。我的结论是,原始文本仅仅是文档错误。

The latest updates to the documentation have removed all of the text on which this question was based. My conclusion is that the original text was simply a documentation error.

这篇关于“立即打包以强制记录的字节对齐”是什么?意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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