各位大侠...谁知道字节对齐或者是字对齐是什么意思
.主要起到什么功能..
为什么要这么做?有什么好处?
(我汇编看了半天不太懂...菜啊..)还有,谁有与判定表相关的内容的东西..
(起码说一下怎么画判定表吧..呵呵..)
.主要起到什么功能..
为什么要这么做?有什么好处?
(我汇编看了半天不太懂...菜啊..)还有,谁有与判定表相关的内容的东西..
(起码说一下怎么画判定表吧..呵呵..)
解决方案 »
- 请问这个??
- 关于用idTcpServer和idTcpClient传送文件的问题
- Delphi代码创建形式规范
- 怎样将外部参数传入rave报表中的一个text上?
- 关于文档中的字符替换
- 用一个EDIT,来作带小数点的数字float型(99.999)输入,代码应该如何?
- 打印报表时可不可以设置一个图片为背图.(关于报表的两个头痛的问题)
- 我有一张光盘,(内含3个完整的不同版的winXP操作系统)!看一下所有文件大小,竟然有1个多G?这是为什么?
- 求金山词霸的MMX半透明窗口代码
- 这怎样用程序实现?
- 为什么我的C/S客户端用CommandText属性连接的表不能ApplyUpdate?
- ACCESS来显示图片
Syntax {$A+}, {$A-}, {$A1}, {$A2}, {$A4}, or {$A8}
{$ALIGN ON}, {$ALIGN OFF}, {$ALIGN 1}, {$ALIGN 2}, {$ALIGN 4}, or {$ALIGN 8}
Default {$A8}
{$ALIGN 8}
Scope Local
ResThe $A directive controls alignment of fields in Delphi record types and class structures.
In the {$A1} or {$A-} state, fields are never aligned. All record and class structures are packed.
In the {$A2} state, fields in record types that are declared without the packed modifier and fields in class structures are aligned on word boundaries.
In the {$A4} state, fields in record types that are declared without the packed modifier and fields in class structures are aligned on double-word boundaries.In the {$A8} or {$A+} state, fields in record types that are declared without the packed modifier and fields in class structures are aligned on quad word boundaries.
Record type field alignment is described in the Delphi Language Guide. See Record types.
Regardless of the state of the $A directive, variables and typed constants are always aligned for optimal access. In the {$A8} state, execution will be faster.
如果以4字节对齐,则分配的内存数为4的倍数,即使只需要1个字节(例如CHAR类型)也是一样。一般使用缺省值即可。如果使用1字节对齐,不会浪费空间,但是效率和可移植性都会差。
a=record
i:char;
j:integer;
end;
b=record
i:integer;
j:integer;
end;
begin
showmessage('a size:'+inttostr(sizeof(a)));
showmessage('b size:'+inttostr(sizeof(b)));
end;
你会发现一个奇怪的问题A B 的大小是一样的,这就因为编译器实现
的是自动对齐的方法,速度快一些
{
char a[5];
long k;
double x;
} baz;
struct
{
double x;
long k;
char a[5];
char pad[7];
} baz; 这个规则同样适用于类的成员的布局。 按数据类型的长度排序本地变量 当编译器分配给本地变量空间时,它们的顺序和它们在源代码中声明的顺序一样,和上一条规则一样,应该把长的变量放在短的变量前面。如果第一个变量对齐了,其它变量就会连续的存放,而且不用填充字节自然就会对齐。有些编译器在分配变量时不会自动改变变量顺序,有些编译器不能产生4字节对齐的栈,所以4字节可能不对齐。下面这个例子演示了本地变量声明的重新排序: 不好的代码,普通顺序 推荐的代码,改进的顺序 short ga, gu, gi;
long foo, bar;
double x, y, z[3];
char a, b;
float baz;
double z[3];
double x, y;
long foo, bar;
float baz;
short ga, gu, gi;
而如果是奇地址则需要两个读写周期。