05.05.2014 16:52, Elena Pourmal пишет:
Privet, Werner and Andrey!
Cannot comment on the topic except to find out what did Andrey mean
under documenting HDF5 C structures… But was impressed with your Russian :-)
I'll try to clarify, with an example.
Consider public function H5Gget_info, which takes 2 arguments:
H5_DLL herr_t H5Gget_info(hid_t loc_id, H5G_info_t *ginfo);
H5G_info_t is described as
/* Information struct for group (for
H5Gget_info/H5Gget_info_by_name/H5Gget_info_by_idx) */
typedef struct H5G_info_t {
H5G_storage_type_t storage_type; /* Type of storage for links in
group */
hsize_t nlinks; /* Number of links in group */
int64_t max_corder; /* Current max. creation order
value for group */
hbool_t mounted; /* Whether group has a file
mounted on it */
} H5G_info_t;
So, ginfo is a pointer to H5G_info_t structure somewhere in the heap or
stack. Please note that H5G_info_t is not a primitive type. I'm not
calling H5Gget_info from C program, so I need to know explicitly how
exactly H5G_info_t members are laid out in memory, to access them. Might
seem straightforward that the layout is (on my w32 machine):
Offset Field
0 byte: storage_type
4 byte: nlinks
12 byte: max_corder
20 byte: mounted
However, I discovered that the actual binary layout is:
Offset Field
0 byte: storage_type
8 byte: nlinks
16 byte: max_corder
24 byte: mounted
So, if I would try to access nlinks at offset 4, I would get incorrect
value.
The reason for layout difference is so-called data structure alignment
(http://en.wikipedia.org/wiki/Data_structure_alignment). It is specific
to compiler and even compiler flags. Alignment settings are neither
specified in the HDF5 documentation explicitly nor are possible to guess
during the run-time.
When HDF5 library is linked statically, the same compiler settings are
used for structs, so they end up binary compatible. Thus, for many C
users it's not a big problem. However, when calling from non-C code, the
same field alignment cannot be applied automatically.
Although, applying *any* alignment greatly complicates the usage of HDF5
functions from non-C code. If no alignment is applied, .h struct
declarations are possible to parse and convert to native code
constructs. If some alignment algorithm comes into play, it additional
non-trivial step.
The above considerations are significant for public structs only. For
private structs, it's no problem in using alignment, for performance or
whatever reasons.
Best wishes,
Andrey Paramonov
--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
_______________________________________________
Hdf-forum is for HDF software users discussion.
[email protected]
http://mail.lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org