Simple array init question

Daniel Keep daniel.keep.lists at gmail.com
Sat Apr 7 23:21:58 PDT 2007



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

-- 
int getRandomNumber()
{
    return 4; // chosen by fair dice roll.
              // guaranteed to be random.
}

http://xkcd.com/

v2sw5+8Yhw5ln4+5pr6OFPma8u6+7Lw4Tm6+7l6+7D
i28a2Xs3MSr2e4/6+7t4TNSMb6HTOp5en5g6RAHCP  http://hackerkey.com/



More information about the Digitalmars-d mailing list