Packed

By default, the compiler automatically aligns fields in records/structs on the Cocoa and Island platforms to 4- or 8-byte offsets (depending on the bitness of the target architecture), by the inserting padding bytes. The Packed aspect marks a record always to have all fields packed together without alignment bytes. This is generally used when writing records directly to files or sockets, or when needing to match an existing memory layout.

Aligned (unpacked) records are faster on most modern CPUs.

type
  [Packed]
  MyStruct = public record
    AByte: Byte;
    AInteger: Int32; // Aligned at byte offset 1; without packed this would be aligned at offset 4.
  end;
[Packed]
public struct MyStruct
{
    byte AByte;
    Int32 AInteger; // Aligned at byte offset 1; without packed this would be aligned at offset 4.
}
@Packed
public struct MyInteger {
    var AByte: Byte;
    var AInteger: Int32; // Aligned at byte offset 1; without packed this would be aligned at offset 4.
}
@Packed
public struct MyInteger
{
    byte AByte;
    Int32 AInteger; // Aligned at byte offset 1; without packed this would be aligned at offset 4.
}

Cocoa and Island Only

The Packed aspect is available on the Cocoa and Island platforms only.