各位大侠...谁知道字节对齐或者是字对齐是什么意思 
.主要起到什么功能..
为什么要这么做?有什么好处?
(我汇编看了半天不太懂...菜啊..)还有,谁有与判定表相关的内容的东西..
(起码说一下怎么画判定表吧..呵呵..)

解决方案 »

  1.   

    Type Switch
    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.
      

  2.   

    字对齐:
    如果以4字节对齐,则分配的内存数为4的倍数,即使只需要1个字节(例如CHAR类型)也是一样。一般使用缺省值即可。如果使用1字节对齐,不会浪费空间,但是效率和可移植性都会差。
      

  3.   

    type 
     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 的大小是一样的,这就因为编译器实现
    的是自动对齐的方法,速度快一些
      

  4.   

    结构体成员的布局   很多编译器有“使结构体字,双字或四字对齐”的选项。但是,还是需要改善结构体成员的对齐,有些编译器可能分配给结构体成员空间的顺序与他们声明的不同。但是,有些编译器并不提供这些功能,或者效果不好。所以,要在付出最少代价的情况下实现最好的结构体和结构体成员对齐,建议采取这些方法:   按类型长度排序   把结构体的成员按照它们的类型长度排序,声明成员时把长的类型放在短的前面。   把结构体填充成最长类型长度的整倍数   把结构体填充成最长类型长度的整倍数。照这样,如果结构体的第一个成员对齐了,所有整个结构体自然也就对齐了。下面的例子演示了如何对结构体成员进行重新排序:   不好的代码,普通顺序 推荐的代码,新的顺序并手动填充了几个字节struct
    {
      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;  
      

  5.   

    8086学习过程中我们知道如果数据的地址是偶地址读写一个WORD数据只用一个读写周期,
    而如果是奇地址则需要两个读写周期。