How to read tightly packed array of vertices into a struct of different size?

I have the following format stored in an HDF5 file (tightly packed array of vertices):

struct DiskVertex
    float pos[3];

And I have a memory buffer of vertices I want to read this data into:

struct MemVertex
    float pos[3];
    float normal[3];
    float uv[2];

For example, if there were DiskVertex[1000] on disk, and a memory buffer of MemVertex[1000].

How can I read the data from DiskVertex into MemVertex? I want to avoid allocating a temporary buffer, reading the array into it, then copying that data into the destination. I’m not sure how to specify the data transfer options for this.


If the dimension is indeed 1000 you are adding code complexity for little to no gain. In any other cases, where N is on different scale, you read data into a buffer then you scatter it into to your MemVertex structure. (inverse of gather operation)

This will make it work for you, but it introduces a design flaw: non-coalesced memory access. you are to lose significant bandwidth The alternative representation where each field is a separate vector you get the best performance – when loading data, at the cost of code complexity – you have to add a multiplexer.
Here is my presentation slide for the problem.

best: steve

Steve - thanks for the reply. The 1000 was an example, and the MemVertex is in a std::vector. I’ll take a look at your slides and will respond if I have further questions.

Thanks, Dennis