Specify the memory alignment of an opaque type

When the database server passes an opaque data type to a UDR, it aligns the data on a certain byte boundary. By default, the database server uses a four-byte alignment for the internal representation of an opaque type. Four bytes is the standard alignment for 32-bit platforms.

On 64-bit platforms, alignment must be eight bytes.

You can specify a different memory-alignment requirement for your opaque type with the ALIGNMENT modifier of the CREATE OPAQUE TYPE statement. The database server stores the value of the ALIGNMENT modifier in the align column of the sysxtdtypes system catalog table.

Actual alignment requirements depend on the C definition of the opaque type and on the system (hardware and compiler) on which the opaque data type is compiled. The following table summarizes valid alignment values for some C data types.
Value for ALIGNMENT modifier Meaning Purpose
1 Align structure on one-byte boundary Structures that begin with one-byte quantities
2 Align structure on two-byte boundary Structures that begin with two-byte quantities, such as mi_unsigned_smallint
4 (default) Align structure on four-byte boundary Structures that begin with four-byte quantities, such as mi_real or mi_unsigned_integer
8 Align structure on eight-byte boundary Structures that contain members of the mi_double_precision data type

Arrays of a data type must follow the same alignment restrictions as the data type itself. However, structures that begin with single-byte characters (such as mi_boolean or mi_char) can be aligned anywhere.

When you obtain aligned data for an opaque data type from a varying-length structure, use the mi_get_vardata_align() function. Make sure that the align argument of mi_get_vardata_align() matches the value of the align column in the sysxtdtypes system catalog table for the opaque type. For example, the mi_double_precision data type is aligned on an eight-byte boundary. If an opaque type contains an array of mi_double_precision values, use mi_get_vardata_align() with an align value of 8 to access the data portion of the mi_double_precision array.

The following call to mi_get_vardata_align() obtains data that is aligned on eight-byte boundaries from the var_struc varying-length structure:
opaque_type_t *buff;
mi_lvarchar *var_struc;
...
buff = (opaque_type_t *)mi_get_vardata_align(var_struc, 8);