Direct Access of Compound Datatypes from user application

Dear list,

First of all, my apologies if the question may be silly, but I am new
to HDF5, therefore I would like to double check if my understanding is
correct or not.

Considering the example "h5_compound.c"
<https://www.hdfgroup.org/ftp/HDF5/current/src/unpacked/examples/h5_compound.c>,
it shows how to define different user-defined datatypes (s1_t, s2_t
and s3_t) and query back the stored data in the form I would prefer
("all data" with s1_t, or partial/selection by using s2_t or s3_t).
In this example, the workflow is as follow:
1) The H5 file is populated by _writing_ s1_t instances;
2) then I can read it back, or in the form of s2_t or s3_t.
Now, I do what I want with "s2" data that I got, I modify it (e.g, I
multiply by 10 all its elements
  > for( i = 0; i < LENGTH; i++){ s1[i].c = s1[i].c * 10;}
) and I would like to store these changes to the HD5F, that is
3) I must write s2 back in the selected chunk of the dataset.
4) If now I would like to query the whole s1_t, I should read again the dataset.

In short: everything works by "copying". In my code application, I
must allocate (and manage by myself) the data I will use to store the
query from a file, and merge the changes back by writing (so copying
the content of my user-defined and allocated memory).

My question is then the follow: is it possible to query, instead of
copying of the content of the chunk of the file asked, the memory
address (so direct access, pointing to the data) of where that data is
stored?
Of course, this may make sense only if some specific conditions, that
is when the HDF5 file is not persistent, by using the driver "core"
(all in memory), and asking for contiguous memory allocation and so
on.
Therefore, I would like to know if it is possible to get the pointer
to that datatype - any content changes is reflected directly, I don't
need to "write" anymore.
Pointing on the same instance of s1_t with s1_t and the subset s2_t,
any change on s2_t is reflected on the pointer over s1_t.
(just to make it clear....once I get the address, I would like to do
something like the follow:

s2[0]->c = 11;
printf("%d\n,s1[0]->c); --> prints '11'

'11' is also stored in the HDF5 file
)

So far, my answer is that is not possible. I did not find any answer
or example online, and I don't think the hobj_ref could solve that. or
yes?

Rationale:
I think I don't find any example of it because it is not possible,
and, furthermore, it is wrong in the HDF5 context. HDF5 is for storing
data, where the library itself is making memory management.
For my understanding, It would be like by-passing the features of the
library itself. That is, the answer to my question is no, and even
more, attempting to do so would be a wrong usage of the HDF5 library).

I hope my question is clear enough - my apologies if it is not!

Cheers,
- Enea Scioni

You can get the offset to a dataset within the file with the function
getOffset(). You can also get the size of each record. So you can
mmap the file and read the raw data at the right place. We do this
for our libtinyhtm library (see lines 58-130)

  https://github.com/Caltech-IPAC/libtinyhtm/blob/master/src/tree.cxx

Cheers,
Walter

···

Enea Scioni <scnnee@unife.it> wrote:

My question is then the follow: is it possible to query, instead of
copying of the content of the chunk of the file asked, the memory
address (so direct access, pointing to the data) of where that data is
stored?
Of course, this may make sense only if some specific conditions, that
is when the HDF5 file is not persistent, by using the driver "core"
(all in memory), and asking for contiguous memory allocation and so
on.
Therefore, I would like to know if it is possible to get the pointer
to that datatype - any content changes is reflected directly, I don't
need to "write" anymore.
Pointing on the same instance of s1_t with s1_t and the subset s2_t,
any change on s2_t is reflected on the pointer over s1_t.
(just to make it clear....once I get the address, I would like to do
something like the follow:

s2[0]->c = 11;
printf("%d\n,s1[0]->c); --> prints '11'

'11' is also stored in the HDF5 file
)