Comment

Comment by ryanpepper

I was taught to do it like this in C:

  double *a = malloc(sizeof(double)*nx*ny*nz);
  int id;
  for(int k = 0; k < nz; k++) {
      for(int j = 0; j < ny; j++) {
          for(int i = 0; < i < nx; i++) {
              id = k*nx*ny + j*nx + i;
              a[id] = /* some mathematical operation */
          }
      }
  }
You can do it in other ways (arrays of pointes, etc), but I think this is probably the simplest conceptually, and the memory is contiguous.
parent ryanpepper 9 years ago

No comments yet

Be the first to share your thoughts.

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton