Skip to content

Can we write a 2D array with dynamic shape? #767

Closed Answered by 1uc
ziyuang asked this question in Questions
Discussion options

You must be logged in to vote

The downside of this is that when presented with a float** we can't know if it's contiguous or not, e.g.

float ** array = (float**) malloc(n * sizeof(float*));
for(size_t i = 0; i < n; ++i) {
    array[i] = malloc(m * sizeof(float));
}

// vs
float * data = (float*) malloc(n*m * sizeof(float));
float ** array = (float**) malloc(n*sizeof(float*));

for(size_t i = 0; i < n; ++i) {
  array[i] = data + i * n;
}

Currently, HighFive doesn't seem to respect the possibility of non-contiguous pointer-to-pointer. Hence, it might work. However, the version I posted should be preferred.

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
2 replies
@1uc
Comment options

Answer selected by ziyuang
@ziyuang
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants