Simple array init question

Chris Nicholson-Sauls ibisbasenji at gmail.com
Sat Apr 7 21:00:25 PDT 2007


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



More information about the Digitalmars-d mailing list