pTAL Conversion Guide

Structures
pTAL Conversion Guide527302-002
11-31
REFALIGNED(2)
REFALIGNED(2)
When a structure pointer specifies REFALIGNED(2), the base of the structure might or
might not be well-aligned for access on native architecture. When you reference the
pointer in an expression, pTAL generates conservative code that might not be as
optimal as the code it generates when you specify REFALIGNED(8).
When you use a structure pointer in an executable statement, the field to which the
pointer refers might not be well-aligned. For example, if you are accessing a structure
whose address was passed as a parameter to a procedure, you might not know
whether the field is well-aligned. Although the fields of the structure are well-aligned
from the base of the structure, the base of the structure might not be well-aligned in
memory.
Similarly, if you reference a field in a structure that is stored at an arbitrary address on
a heap, you might not know in advance whether the fields in the structure are well-
aligned.
To ensure good performance, use REFALIGNED(2) to access the field, even if it
happens to be well-aligned. You must always use REFALIGNED(2), unless you are
certain that nearly all fields referenced by the pointer are well-aligned.
STRUCT s3 FIELDALIGN(AUTO);
BEGIN
INT i;
INT(32) j;
END;
INT .p1(s1); ! Reference alignment is 2
INT .p2(s2); ! Reference alignment is 8
INT .p3(s3); ! Reference alignment is 2 on TNS architecture,
! 8 on native architecture
Example 11-14. REFALIGNED(2) (page 1 of 2)
WADDR a_str;
STRUCT s_templ(*) FIELDALIGN(SHARED8);
BEGIN
INT i;
FILLER 2;
INT(32) j;
END;
Example 11-13. Default Reference Alignment (page 2 of 2)