digitalmars.D.learn - Template
- Mael (25/25) Jun 06 2008 Hello,
- Jarrett Billingsley (8/22) Jun 06 2008 If you declare a two-dimensional (not sure about more dimensions..)
- Mael (5/7) Jun 06 2008 And what prevents the compiler to represent int[3][] arrays as "single-d...
- Jarrett Billingsley (10/18) Jun 06 2008 Ah, it seems that both are treated the same. If you make such an array:
- Mael (1/3) Jun 06 2008 Well, using dmd 1.30 with -O -release gives a two-dereference code, but ...
Hello, another question, I wanted to generate an image having an arbitrary dimension (each pixel is a n-tuple). The option class Image(vType, int vDim) { ... vType[vDim][] data ; } isn't really good, because the array isn't "unfolded" resulting in some overhead (or is there a way to build a vType[dim][n] array that would be represented as a vType[n*dim] array, and the compiler would optimize arr[p][k] in arr[p*dim+k] ?) so I wanted to have a template generate a struct that would look like struct tuple { vType elem1 ; vType elem2 ; ... } and define the data as { ... tuple[] data ; } (I guess this would give what I expect). I couldn't get to do this with template metaprogramming, could anyone give a hint on how to recurse to build such a struct ? Thanks
Jun 06 2008
"Mael" <mael.primet gmail.com> wrote in message news:g2bbpi$10n4$1 digitalmars.com...Hello, another question, I wanted to generate an image having an arbitrary dimension (each pixel is a n-tuple). The option class Image(vType, int vDim) { ... vType[vDim][] data ; } isn't really good, because the array isn't "unfolded" resulting in some overhead (or is there a way to build a vType[dim][n] array that would be represented as a vType[n*dim] array, and the compiler would optimize arr[p][k] in arr[p*dim+k] ?)If you declare a two-dimensional (not sure about more dimensions..) fixed-size array of fixed-size arrays, like "int[4][4]", it will be treated as a rectangular array and not as an array of arrays. They are mentioned here: (http://www.digitalmars.com/d/1.0/arrays.html) in the "Rectangular Arrays" section. :)
Jun 06 2008
If you declare a two-dimensional (not sure about more dimensions..) fixed-size array of fixed-size arrays, like "int[4][4]", it will be treatedAnd what prevents the compiler to represent int[3][] arrays as "single-dimensional" 3*length array, since this is what it would do in case the declaration was struct triple { int a, b, c ; } triple[] my_array ; ?
Jun 06 2008
"Mael" <mael.primet gmail.com> wrote in message news:g2biok$1epu$1 digitalmars.com...Ah, it seems that both are treated the same. If you make such an array: int[3][] a; a.length = 5; You'll find that the data for all the elements is contiguous, as with structs. I wouldn't be surprised if the compiler would access the values in it using one pointer dereference instead of 2. Fixed size arrays are weird, sometimes they're reference types and sometimes they're value types. It's hard to remember when :SIf you declare a two-dimensional (not sure about more dimensions..) fixed-size array of fixed-size arrays, like "int[4][4]", it will be treatedAnd what prevents the compiler to represent int[3][] arrays as "single-dimensional" 3*length array, since this is what it would do in case the declaration was struct triple { int a, b, c ; } triple[] my_array ;
Jun 06 2008
structs. I wouldn't be surprised if the compiler would access the values in it using one pointer dereference instead of 2.Well, using dmd 1.30 with -O -release gives a two-dereference code, but maybe there's a compiler option to change this behavior ?
Jun 06 2008