Last active
August 29, 2015 14:17
-
-
Save jg-you/c051535b7878edc39d55 to your computer and use it in GitHub Desktop.
HDF5, C interface: From jagged array to variable lenght
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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