Initialization of dynamic multidimensional array

Daniel Kozak via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Feb 5 13:14:33 PST 2017


http://stackoverflow.com/questions/24600796/d-set-default-value-for-a-struct-member-which-is-a-multidimensional-static-arr/24754361#24754361


Dne 5.2.2017 v 21:33 berni via Digitalmars-d-learn napsal(a):
> With X not known at compile time:
>
>> auto arr = new int[][](X,X);
>> for (int i=0;i<X;i++)
>>   for (int j=0;j<X;j++)
>>     arr[i][j] = -1;
>
> Is there anything better for this? I mean, the program will fill the 
> array with zeroes, just to overwrite all of them with -1. That's 
> wasted execution time and doesn't feel D-ish to me.



More information about the Digitalmars-d-learn mailing list