30.06.2012 22:21, Vidar Wahlberg пишет:
I know multidimensional arrays has been brought up many times, although
I was not able to find a clear answer to my question. My knowledge of
what's going on behind the curtains is somewhat lacking, please correct
me if my assumptions are incorrect.
Creating a dynamic multidimensional array can be easily achieved with
for example "auto matrix = new int[][](4, 2);", although if I've
understood it correct this would create a "jagged" array (as explained
on page 112 in TDPL) which may cause efficiency issues due to two
indirections as opposed to only one indirection which you would have in
a "rectangular" array (as explained at http://dlang.org/arrays.html). If
you at compile time know the dimensions of the array you could write
"int[2][4] matrix;", and I've understood this as creating a
"rectangular" array.
In my case I don't know the dimensions at compile time, but I'm still
interested in creating a multidimensional array with only one
indirection (i.e. allocated contiguously in memory) at runtime, where
I'm not going to modify the size of the array. Is this impossible* in D?
*I know I could create a one-dimensional array and programmatically
convert from multiple dimensions to one dimension, yet this is not as
satisfactory as a "true" multidimensional array.
Obviously it's the efficiency I worry about, I would much appreciate if
someone could shed light upon this.
You could be interested in my answer on this thread:
http://forum.dlang.org/thread/mailman.1578.1339962782.24740.digitalmars-d-le...@puremagic.com
But looks like nobody really need such implementation (nobody asked me
to make it up-to-date or put under VCS).
--
Денис В. Шеломовский
Denis V. Shelomovskij