CodeCogs - An iteractive open source Numerical library Welcome... Login
CodeCogs
shopping cart
OSXWindowsLinux
Search CodeCogs
Numerical Components

Valid RSS

Array

Cube

Available under GPL (Free) and Commercial licence
get a GPL licence
COST (GBP)
this unit 0.31
sub units 0.30
add a commercial licence to your cart
0
viewed 6815 times and licensed 110 times

Dynamically allocates a zero_based 3D block (cube) of data.

Further Info Controller: will  Contact Controller
+View version details
Contents hide toc
buy now     get GPL     add to cart

Interface

#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.

Function Documentation

 
template<class T> T***cubelongDepth
longRows
longColumns )[inline]
Dynamically allocates a zero_based 3D cube of memory. This memory block is continuous, and is in column, row, and finally depth order.

1/cube-969.png
+
Ordering of data
The opposite of this function is free_cube.
Example 1:
With an allocation of the type:
#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
Note:
You should always use free_cube to de-allocate memory allocated to this structure.
Parameters:
DepthThe 3rd dimension of a cube.
RowsThe 2nd dimension of a cube.
ColumnsThe 1st (primary) dimension of a cube.
Authors:
Will Bateman (February 2005)
Source Code:

To view or download source code you need either a GPL or Commercial Licence.

buy now     get GPL     add to cart

Not a member, then Register with CodeCogs. Already a Member, then Login.


 
template<class T> voidfree_cubeT***Cube )[inline]
Removes any dynamically allocated memory for a 3D structure from the stack. This function is usually used on data structures created using 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 .
Parameters:
Cubeis the 2D data structure to delete.
Authors:
Will Bateman (February 2005)
Source Code:

To view or download source code you need either a GPL or Commercial Licence.

buy now     get GPL     add to cart

Not a member, then Register with CodeCogs. Already a Member, then Login.


Page Comments

Format Excel Equations

  You must login to leave a messge


Last Modified: 24 Mar 08 @ 21:52     Page Rendered: 2010-03-12 07:06:26

Valid CSS!   Valid XHTML 1.0 Transitional