#include <codecogs/array/cube.h>
using namespace Array;
| template<class T> T*** | cube (long Depth, long Rows, long Columns)[inline] Dynamically allocates a zero_based 3D block (cube) of data. | |
| template<class T> void | free_cube (T*** Cube)[inline] Frees from memory a 3D block of dynamically allocated data. |
| template<class T> T***cube( | long | Depth | |
| long | Rows | ||
| long | Columns | )[inline] |

Ordering of data
#include <stdio.h> #include <codecogs/array/cube.h> int main() { // create a cube 2 deep (0-1), 4 rows (0-3) and 6 columns (0-5) char*** c = Array::cube<char>(2,4,6); for(int i=0; i<6; i++) for(int j=0; j<4; j++) for(int k=0; k<2; k++) c[k][j][i] = i+j+k; for(int i=0; i<(6*4); i++) { if(i % 6 == 0) printf(" "); printf("%hd ",c[0][0][i]); } printf("\n"); for(int i=6*4; i<6*4*2; i++) { if(i % 6 == 0) printf(" "); printf("%hd ",c[0][0][i]); } printf("\n"); Array::free_cube<char>(c); // de-allocated the memory from stack return 0; }Output: (with space between rows)
0 1 2 3 4 5 1 2 3 4 5 6 2 3 4 5 6 7 3 4 5 6 7 8 1 2 3 4 5 6 2 3 4 5 6 7 3 4 5 6 7 8 4 5 6 7 8 9
| Depth | The 3rd dimension of a cube. |
| Rows | The 2nd dimension of a cube. |
| Columns | The 1st (primary) dimension of a cube. |
| template<class T> voidfree_cube( | T*** | Cube | )[inline] |
cube<...>, though it can also be used on other 3D types, so long as the memory is continuously allocated with a pointers to pointers setup.
The opposite of this function is cube .| Cube | is the 2D data structure to delete. |