Skip to content

Instantly share code, notes, and snippets.

@jg-you
Last active August 29, 2015 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jg-you/c051535b7878edc39d55 to your computer and use it in GitHub Desktop.
Save jg-you/c051535b7878edc39d55 to your computer and use it in GitHub Desktop.
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