C 3d array dynamic memory allocation, question, need help -


I was looking through the web to assign space dynamically for 3D matrix, say the int type is. And I've got many sites about 2D matrix, and this was another example shown below. I understand all the above examples, but it can not be related to 3D. Is the manufacturer allocating a location in the backward location or the other? It starts allocating space for the entire matrix, and then does the income in the Z axis? Which I can not understand.

In addition to this, if you know a good site about this, then post it here, it will be appreciated.

  / * Program 9.4 to PTRTUT10.HTM 6/13/97 * / // http://www.taranets.com/cgi/ts/1.37/ts.ws.pl?w = 329; b = 286 #include & lt; Stdio.h & gt; # Include & lt; Stdlib.h & gt; # Include & lt; Stddef.h & gt; Int X_DIM = 16; Int YDIM = 5; Int Z_DIM = 3; Int main (zero) {four * location; Char *** Arr3D; Int y, z; Ptrdiff_t diff; / * First we have set the space on the one side * / space = malloc (X_DIM * Y_DIM * Z_DIM * sizeof (char)); / * Next we allocate the position of an array of points, each pointing to the first element of a 2-dimensional array for finally pointsers * / Arr3D = malloc (Z_DIM * sizeof (char **)); / * And for each of these we assign pointers to a new array * / for (z = 0; z  Z_DIM; z ++) {printf (" Position array% d of% p \ n ", z, * Arr3D [z]); For (y = 0; y  

However, it goes to create indicators for the regions located in space

  Arr3D = malloc (Z_DIM * sizeof (char **));  

The purpose of RR 3D is a way of reaching the place through indexing (specifying z, y, x index). There is only one index in space, so if you want to use the matrix element [a] [b] [c] through space, you have to convert it to a single place [d] where d Y_DIM Z_DIM + b * Z_DIM + c. So with the Arr3D, you can enter through [A] [B] [C] via R3D [A] [B] [C].

RR3D itself is an array, which is an indicator for an array of four signals, then four Arr3D [z] of pointers types. Each Arr3D [z] [y] then points to a specific line with the original 3x3 matrix

  Array3 [z] [y] = space + (z * (X_DIM * Y_DIM) Is set to) + Y * X_DIM);  

Then with ARR [1] [2] you are then reaching a line with z = 1, y = 2 of the matrix.


Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -