Skip to content
English
  • There are no suggestions because the search field is empty.

Change Tables to Match Legacy C Structure Data Alignment

Existing table data may still be aligned with application compiler defaults and not match existing database defaults.

If you use a typical C structure as your data record, your binary field members may be padded by the compiler. Compilers align data for the best performance with modern CPU architectures. This can, of course, be controlled by nearly all modern compilers with a #pragma pack option. 1-byte aligned compiled library and application is an easy way to avoid the issue. However, with either proper packing of the data buffer, or selected 1-byte packed C structures, this is easy to manage. Many legacy c-tree packed byte aligned applications have been ported to current versions with little effort beyond this.

At it's core, c-tree does not consider the schema of your data at all. However, when using interfaces such as C# layers, which depend on our DODA (schema definition resource) then alignment becomes an issue as we must properly interpret existing data in your buffer. If your file is defined with a specific alignment (we maintain those attributes in both our header and the DODA resource itself), then there are no issues as we will use what the chosen alignment is. You do have to consider it when creating the file to coordinate this alignment with  your desired data record buffers. In fact, most existing legacy files can be maintained as pack byte aligned, and newer ones with default 4 or 8-byte compiler alignment.

  • Use ctinfo or DrCtree to verify your current c-tree data/index file alignment
  • ctheader utility can change the file header values
  • UpdateHeader API with ctALIGNhdr mode

Unless you're processing extremely large volumes of binary data management, it's doubtful you'll measure any performance differences. Many successful applications hum along as 2-byte aligned and no one knows the better. Structure padding by the compiler is relatively modest in most cases, frequently only 1-2 bytes per member, and only for binary values (integers, floating point double, etc.).  And, of course, c-tree can handle files of differing alignments.