template <typename Ty>Ty **alloc2DArray(int width, int height){ Ty **arr = new Ty*[height]; for(int i=0; i<height; i++) { arr[i] = new Ty[width]; } return arr;}
template <typename Ty>void free2DArray(Ty **&arr, int height){ for(int i=0; i<height; i++) { delete []arr[i]; arr[i] = 0; } delete []arr; arr = 0;}
int **imatrix( int w, int h ) { int i; int **m;
m = new int * [h]; if( !m ) PutError("memory alloc failure in imatrix()"), exit(0);
m[0] = new int [ w * h ]; if( !m[0] ) PutError("memory alloc failure in imatrix()"), exit(0);
for( i = 1; i < h; i++ ) { m[i] = &m[0][ i * w ]; } return m; }