title: D language: initializing dynamic multidimensional array best practices?
body: <p>Just curious if this is the best practice for initializing a dynamic, multidimensional array in <a href="http://www.d-programming-language.org/index.html">D</a>.  There is a section on arrays in their language reference, but I'm not quite sure if it goes over what I'm trying to accomplish.</p>
  
  <pre><code>class Map {
      Tile[][] tiles;
  
      this(uint width, uint height) {
          tiles.length = height;
          foreach (ref tilerow; tiles)
              tilerow.length = width;
      }
  }
  
  Map map1 = new Map(5000, 3000); // values determined at runtime
  </code></pre>
  
  <p>(or an equivalent alternative like a typical for (y=0;y&lt;height;y++) loop).</p>
  
  <p>My concern with this is that it reallocates each row of the array separately rather than the whole chunk all at once, so I don't know if this will lead to too much memory shuffling.  Also, I believe it's not guaranteed to be contiguous (since <strong>tiles</strong> is just an array of pointers in this case).  Is there any "better" way to do this (that doesn't involve using a single-dimensional array and computing the index myself)?  As far as I can tell from the docs a contiguous multidimensional array can only be declared with immutable dimensions at compile time, just wondering if I'm missing something...</p>