January 15, 2019
Upgrade any version of c-tree with Legacy Data Alignment
c-treeACE can handle files of differing alignments
By FairCom Senior Technical Engineer Craig Bailey
If you use a typical C structure as your data record, your binary field members may be padded by the compiler. For example, modern versions of Visual Studio and gcc choose alignment based on the binary data type – shorts (two byte) are on two byte boundaries, integers (four bytes) are aligned on four byte boundaries and similarly for eight byte binary types. This can, of course, be controlled by nearly all modern compilers with a #pragma pack option. A 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 fairly easy to manage. Many legacy c-tree packed byte aligned applications have been ported to our current versions with little effort beyond this.
At its core, the c-tree database does not consider the schema of your data at all. However, when using interfaces such as C# layers, which depend on our file 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 file schema resource), then there are no issues as we will use your chosen alignment. You do have to consider it when creating your files and coordinate byte alignment with your desired data record buffers, that is, based on your C data record structures and/or current compiler alignment. 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
- ctalgn utility can change the file header values
- UpdateHeader API with ctALIGNhdrmode can set these values as needed
Compilers align data for the best performance with modern CPU architectures. However, 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 with no one knowing. 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, again, c-treeACE can handle files of differing alignments.
If you are using an older version of c-tree, we encourage you to call us at 1-800-234-8180 to learn more about the capabilities and robust feature set of c-treeACE. Or click here for additional contact information.
Note: This information is for the following versions of c-tree: c-treeACE, c-tree and c-tree Plus.