Simple array init question
Daniel Keep
daniel.keep.lists at gmail.com
Sun Apr 8 02:13:49 PDT 2007
Graham wrote:
> 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.
You *don't* have more than one dimension; you're really nesting arrays.
Strictly speaking, int[5][5] is an (albeit static) jagged array.
I realise that for your purposes, it's six of one, half a dozen of the
other -- I'm just being pedantic :)
-- Daniel
> 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
>>
--
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