pTAL Reference Manual (H06.03+)
Structures
HP pTAL Reference Manual—523746-005
9-25
Optimizing Structure Layouts
Structures that specify SHARED8 field alignment, however, require you to explicitly
declare filler items to force fields to be well-aligned, as previously described. You might
be able to reduce the size of a structure if you can arrange its fields to minimize the
number of filler items required.
In Example 9-16 on page 9-25, the structure s2 has the same fields as s1 in
Example 9-15 on page 9-25, but s2 has SHARED8 field alignment and includes filler
items where required. Offsets are shown in bytes. s2 is 32 bytes.
s2 has SHARED8 field alignment, and uses 14 more bytes than s1. If the order of the
fields within the structure is not important; however, you can rearrange the fields so
that the structure contains fewer bytes, as shown in Example 9-17 on page 9-25.
Example 9-15. Structure With SHARED2 Field Alignment
STRUCT s1 FIELDALIGN(SHARED2);
BEGIN
INT i; ! i begins at offset: 0
INT(32) j; ! j begins at offset: 2
STRING s1; ! s1 begins at offset: 6
STRING s2; ! s1 begins at offset: 7
FIXED f; ! f begins at offset: 8
INT k; ! k begins at offset: 16
END; ! Total length of s1: 18 bytes
Example 9-16. Structure With SHARED8 Field Alignment
STRUCT s2 FIELDALIGN(SHARED8);
BEGIN
INT i; ! i begins at offset 0
FILLER 2; ! 2 bytes of filler
INT(32) j; ! j begins at offset 4
STRING s1; ! s1 begins at offset 8
STRING s2; ! s2 begins at offset 9
FILLER 6; ! 6 bytes of filler
FIXED f; ! f begins at offset 16
INT k; ! k begins at offset 24
FILLER 6; ! Pad to a multiple of the widest field (f)
END; ! Total length of s2: 2 bytes
Example 9-17. Optimized Structure With SHARED8 Field Alignment
STRUCT s3 FIELDALIGN(SHARED8);
BEGIN
INT i; ! i begins at offset 0
STRING s1; ! s1 begins at offset 2
STRING s2; ! s2 begins at offset 3
INT(32) j; ! j begins at offset 4
FIXED f; ! f begins at offset 8
INT k; ! k begins at offset 16
FILLER 6; ! Pad to a multiple of the widest field (f)
END; ! Total length of s3: 24 bytes










