Mail Archives: djgpp/1998/07/11/12:45:45
On Thu, 9 Jul 1998, temujin wrote:
->> You could say:
->> int* test = new int[64];
->> And then use test[x*8+y] to resolve test[x][y].
->> Or, if the dimensions are constants, don't dynamically allocate.
->If you *MUST* use dynamic arrays and want to do it with
->OBJECTS/structures you have to remember to
->WHATEVER **myarray=malloc......
->Have to have the double pointer thing to make it an array of pointers
->which point to objects. With just *myarray you create an array of
->unique and seperate objects.
But, if you do it that way, you then have to go through the loop
and allocate memory (with new or malloc) for each pointer:
char** a = new (char*)[8];
for(int c=0; c<8; c++) a[c] = new char;
That's alot more fuss (and requires memory for allocation overhead
than just allocating one 64 char block and treating it like a 2d array.
Endlisnis
[I have a pyramid of wingyness]
- Raw text -