If I wrote a language...

Multidimensional arrays would be stored as arrays of arrays. This is nice for several reasons - one being that large arrays are fragmented. It also makes jagged arrays possible - and jagged arrays are awesomely useful. It also means that since each "row" is just an array (stored as a pointer/reference) you can manipulate the row as an array. You don't have to copy the contents of the row into a new array to get just a subset of the data from the multidimensional array. (I'm looking at you, Excel)

Come to think of it, maybe you'd have the option of using array-of-arrays or contiguous arrays, because you can do some cute stuff if your multidimensional arrays are contiguous in memory. (Apparently C++ does it this way.)

2 things about

If I wrote a language...
  1. And here I was just in the process of swearing off any array with more than 2 dimensions....

    I'm sure I'll change my mind in a week, but for now I'm thinking that arrays of dimension higher than 2 were only invented for the benefit of lazy engineers. For applications in my field, they're useful insofar as it makes for nice, neat and convenient loop control structures to cycle over the data - but it runs slow and makes vectorization harder.

    It's a long story to go further, but when it comes time to parallelize a program, I've found that life would have been easier if the original designer had eschewed the 3 and 4 dimensional arrays that seemed so convenient in the serial-computing world.

    Anyway... more actually on topic of your post...jagged arrays always seemed like a good idea to me for 2 dimensions.

  2. I think I've only ever used an array of greater than 2 dimensions *once*. [Probably a 3D array to hold data that was conceptually 3D]. I can see where the idea of multiple dimensions in math would "naturally" map to multidimensional arrays, but I can also see the computing horror that would cause.

    The old programmer-friendly versus machine-friendly dilemma, eh?

    ... and I really love jagged [2D] arrays. They're sexy!


Copyright 2012 Phile not Found. See About
Powered by Blogger

"Whenever you find that you are on the side of the majority, it is time to pause and reflect."