Simple array init question

Graham grahamamacdonald at gmail.com
Sun Apr 8 01:35:26 PDT 2007


A bit of confusion here:-)  Yes, it's a simple, static fixed size, 
multi-dimensional array.  I could use a 1D array, but I wanted to try 
out the 2D approach and was puzzled why I couldn't use the initialiser 
for the entire array if I had more than one dimension.  There's nothing 
more to this!

Thanks.

Daniel Keep wrote:
> 
> Chris Nicholson-Sauls wrote:
>> Daniel Keep wrote:
>>> Graham wrote:
>>>> A floating point texture buffer - 3 floats per pixel, and (say) 640x480
>>>> pixels.
>>>>
>>>> Manfred Nowak wrote:
>>>>> Graham wrote
>>>>>
>>>>>> several thousand elements large.
>>>>> In what domains do one need to represent dense multidimensional
>>>>> structures with O(1) time for accesses of elements?
>>>>>
>>>>> -manfred 
>>> Perhaps you shouldn't be using jagged arrays, then.  int[][] is *NOT* a
>>> multidimensional array.  It's basically equivalent to this:
>>>
>>> struct int_array
>>> {
>>>     int* ptr;
>>>     size_t length;
>>> }
>>>
>>> struct int_array_array
>>> {
>>>     int_array* ptr;
>>>     size_t length;
>>> }
>>>
>>> int_array_array buffer;
>>>
>>> Notice those nested pointers; that means that your texture is not
>>> necessarily contiguous in memory, which would make, for example, loading
>>> the texture into GL a pain in the behind.  Not sure if the cache would
>>> have problems...
>>>
>>> I think there's a few multidimensional array templates floating
>>> around... or if not, you can always write your own :)
>>>
>>>     -- Daniel
>>>
>> Actually, /IF/ he's using static/fixed-length arrays, then as I
>> understand it this ceases to be true.  That is, static arrays are solid
>> blocks of memory -- and I assume this stays the same for
>> multi-dimensional arrays.  Of course, /IF/ he's using dynamic-length
>> arrays, then you're absolutely correct about it being likely opposite.
>>
>> -- Chris Nicholson-Sauls
> 
> Ah yes, of course.  Sorry; bit dense today :P
> 
> 	-- Daniel
> 



More information about the Digitalmars-d mailing list