[ HDF5 High Level Tutorial Top ] [ Next ] [ Prev ]

H5TB: HDF5 Table
Tables

The table programming model

In the Table programming model the user has to obtain an identifier of the group or file where he or she wants to use the Table functions and then call the appropriate function. For example

/* Create a new HDF5 file using default properties. */
file_id = H5Fcreate( "my_table.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT );

/* Call some TB function */
H5TBsome_function( file_id, ...extra parameters );

/* Close the file. */
status = H5Fclose( file_id );

Alignment of structure fields

In the following examples we use a structure called Particle, that intends to represent an hypothetical particle. This particle has a name, a position (specified by latitude and longitude), pressure and temperature. The structure is defined as

typedef struct Particle 
{
char name[16];
int lati;
int longi;
float pressure;
double temperature; 
} Particle;

This is an example of the sizes in bytes associated with the Particle structure, and their layout as they are packed and written to disk by the H5TBmake_table function . The size of this structure is 36 bytes.

name lati longi pressure temperature
16 4 4 4 8

The byte-offset of fields within structures is compiler dependent. On memory this layout can be different. Here is an example of the memory layout for Intel86 architecture running the Microsoft Visual Studio compiler. 

name lati longi pressure padding temperature
16 4 4 4 4 8

The size of this structure in memory is 40 bytes. 4 bytes of padding are inserted to make "pressure" (being a 4-byte value) start on a 4-byte boundary in memory. This (putting an n-byte item at an n-byte boundary) is called "natural alignment". It is done because most CPUs can access data faster if it is naturally aligned.  

Some compilers have means to force a specific structure alignment, but this is highly compiler-specific and therefore can't be used in a portable program. To deal with this the H5LT API provides an pack/unpack function, H5LTrepack, that, when reading data to memory, ignores this padding. The offsets and size of this structure are needed for the read functions of the table API. The H5TBread_table function uses this repack function to read valid data into memory.


HDF Help Desk
Last modified: November 18, 2002