Skip to content

Instantly share code, notes, and snippets.

@jg-you jg-you/HDF5VL.cpp
Last active Aug 29, 2015

Embed
What would you like to do?
HDF5, C interface: From jagged array to variable lenght
// Test data
std::vector< std::vector<int> > jagged_array(3);
jagged_array[0] = {0};
jagged_array[1] = {0, 1, 2, 3};
jagged_array[2] = {0, 1, 2};
hvl_t * X = (hvl_t *)malloc(jagged_array.size() * sizeof(hvl_t))
for (unsigned int i = 0; i < jagged_array.size(); ++i) {
X[i].len = jagged_array[i].size();
int * ptr = (int *) malloc (X[i].len * sizeof(int));
for (unsigned int j = 0; j < X[i].len; ++j) {
ptr[j] = jagged_array[i][j];
}
X[i].p = (void *) ptr;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.