"The total size of a static array cannot exceed 16Mb."

Vladimir Panteleev thecybershadow at gmail.com
Tue Oct 2 16:55:38 PDT 2007


On Wed, 03 Oct 2007 02:09:56 +0300, Walter Bright <newshound1 at digitalmars.com> wrote:

> Vladimir Panteleev wrote:
>> That doesn't sound like a big deal, however:
>>
>> 1) when the array is in the data segment, we know the address of
>> every one of its elements - so random access is faster
>
> You might be surprised. Intel has done a great deal of work optimizing
> and pipelining addressing modes. Furthermore, one would probably access
> such an array repeatedly, meaning the pointer to it would be cached in a
> register. I doubt you'll see a dime's worth of difference.
>
> In any case, as has been shown time and again, where one thinks the time
> is spent in a program is always wrong. Even the experts are always
> wrong. Use a profiler!

I will, if I won't be satisfied by the performance :)

>> 2) when using
>> multi-dimensional dynamic arrays, there are more casts
>
> int[1000][] a;
> ...
> a[3][4] = 2;
>
> involves no casts.

Erm... I'm sure I wanted to write something other than "casts" there, but now I even forgot what I wanted to say originally. I think I meant that when you have imbricated dynamic arrays, there are even more dereferences.

>> 3) rectangular
>> static arrays are much faster when you want to access it by column -
>> you just add (width*element_size) to the pointer, and go to the
>> element on the next row
>
> It's the same for int[1000][]

Right. I always overlook that case!

>> 4) when you want to access an address inside
>> the element (you have an array of structs), you must perform an
>> addition after the multiplication (I think it can be part of the
>> instruction in the newer instruction sets though) - while, when the
>> array base address is predetermined, you can just use base_address +
>> element_offset as the base address, then add index*element_size to
>> that etc.
>
> Using the address mode offset[reg1][reg2*size] mode is not any slower
> than using offset[reg2*size].

Yes... that's the one I mentioned (though I'm used to see it as [reg+reg2*size+offset]).

Thanks for replying. I wonder how hard would it be to write - or, at least, start a community project of a Windows PE linker written from scratch - in D, of course :)

-- 
Best regards,
 Vladimir                          mailto:thecybershadow at gmail.com



More information about the Digitalmars-d mailing list