Friday, 15 March 2013

How can I dynamically allocate memories for 4-D array with 2-D fixed array in c++ -


How can I dynamically allocate memories for a 4-D array with a 2-D fixed array in C-5

I know how to specify a 3-D array with a 2-D fixed array like this

  int n = 100; Double (* A) [4] [5]; A = new double [n] [4] [5];  

But in the case of 4-D, what should I do?

  int n = 100; Int m = 1000; Double (* (* A)) [4] [5]; A = new double [m] [] [4] [5] ???  

It is possible to avoid this problem using the quadruple indicator (double **** A), but I need the matrix ([4] [5]) in my code system Please help

Instead of using pointer and keeping track of memory, you should use a vector.

  vector & lt; Vector & lt; Vector & lt; Vector & lt; Integer & gt; & Gt; & Gt; & Gt; Vector4d (dim1, vector & lt; vector & lt; vector & lt; int & gt; & gt; (dim2, vector & lt; vector & lt; int & gt; & gt; (4, vector & lt; ; Int> (5, 0)))  

No comments:

Post a Comment