Well... off the top of my head, I would do something like this:
typedef char byte;#include <stdlib.h> #include <memory.h> byte** allocArray(int xDim, int yDim) { int i; byte** array2D; byte* buf; buf = malloc(xDim * yDim + (xDim*sizeof(byte*))); array2D = (byte**)buf; for(i=0; i<xDim; i++) array2D[i] = &buf[i*yDim + (xDim*sizeof(byte*))]; #ifndef NDEBUG memset(&array2D[0][0], 0xcd, xDim*yDim);#endif return array2D; }void freeArray(byte*** array) { free((void*)(*array));#ifndef NDEBUG *array = 0;#endif } int main() { int i, j; byte** myarray = allocArray(10, 12); for(i=0; i<10; i++) for(j=0; j<12; j++) myarray[i][j]= 1; freeArray(&myarray); return 0; }
edit: include bug...
[edited by - Magmai Kai Holmlor on July 30, 2002 12:28:52 AM]
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara