[D1,static array] fill static multidimensional array.

%u e at ee.com
Thu Oct 21 18:50:56 PDT 2010


What is the fastest way to fill a static multidimensional array?

Looping over all dimension's elements sounds inefficient, especially as a
static array is essentially continuous memory.
What is the best practice?

int[2][2][2] arr = 0;
arr[] = 3; //Error: cannot implicitly convert expression (3) of type int to
int[2u][2u][]
arr[][][] = 3; // this would be fine too :)

int[2][2][2] arr2 = [[[1,2],[3,4]],[[5,6],[7,8]]];

Somehow I find it surprising that this copies the whole array.
arr[] = arr2;


More information about the Digitalmars-d-learn mailing list