What does “Packed Now Forces Byte Alignment of Records” mean?

前端 未结 4 663
一生所求
一生所求 2020-12-24 13:19

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

Packed Now Forces Byte Alignment of Records

If you have legacy code that uses the

4条回答
  •  生来不讨喜
    2020-12-24 14:12

    As I am not the Delphi compiler guy I can also mostly guess as others did: The record alignment might not be meant for aligning the members inside the record, but the record itself instead.

    If you declare a record variable it is aligned to some address in memory, that is most likely aligned on a 4-byte boundary. This has been the case (as tested in D2007) for packed and unpacked records.

    Now in XE2 a packed record is placed in a 1-byte boundary, while unpacked records are placed on some even boundary, which can be controlled by the align keyword. Like this:

    type
      TRecAligned = record
        b1: byte;
        u1: uint64;
      end align 16;
    
      TRecPackedAligned = packed record
        b1: byte;
        u1: uint64;
      end align 16;
    

    The packed record is still aligned on a 1-byte boundary while the unpacked record is aligned to a 16-byte boundary.

    As I said, it is only a guess. The wording of the Embarcadero quote isn't that much clear on the suject.

提交回复
热议问题