Just wondering if this is the best practice for initializing a dynamic multidimensional array in D. There is a section on arrays in their language links, but I'm not quite sure if this is what I'm trying to accomplish.
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);
(or the equivalent alternative, as usual for a loop (y = 0; y <height; y ++)).
My concern about this is that it redistributes each row of the array separately, and not the entire fragment at the same time, so I donโt know if this will lead to too much memory shuffling. In addition, I believe that this is not guaranteed to be contiguous (since tiles are just an array of pointers in this case). Is there a โbetterโ way to do this (this does not involve using a one-dimensional array and calculating the index itself)? As far as I can tell from the docs, an adjacent multidimensional array can only be declared with immutable dimensions at compile time, just wondering if something is missing ...
multidimensional-array d
ccjuju
source share