Random thought on this dynamic multidimensional array stuff:

int **new_array(int rows, int cols) {
  int size = (cols + 1) * rows;
  int **ary = new int* [size];
  int **i = ary;
  while (i < ary + size) {
    ary[i] = i + 1;
    i += cols + 1;
  }
  return ary;
}

Now you get an int** which you can index thusly[a][b];
the entire thing is, however, one large array, delete [] ary; is
sufficient.
messy creation, but a snap to clean up. if only dinner was that way.
Some drawbacks, it only works for ints. You may have type issues, but
not that I can tell.
Pros: you don't use any more space than other ways, but it's all
contiguous. (Hopefully you have the contiguous room).
One thing to delete (as mentioned already).

Anyway, this was just a quick and dirty idea thrown together, I'm sure
it's got issues (syntactical ror otherwise). I would love nothing more
than to have this thing blown to pieces by those smarter than me ;)

Von Fugal

Attachment: signature.asc
Description: Digital signature

--------------------
BYU Unix Users Group 
http://uug.byu.edu/ 

The opinions expressed in this message are the responsibility of their
author.  They are not endorsed by BYU, the BYU CS Department or BYU-UUG. 
___________________________________________________________________
List Info: http://uug.byu.edu/cgi-bin/mailman/listinfo/uug-list

Reply via email to