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

Walter Bright newshound1 at digitalmars.com
Tue Oct 2 16:09:56 PDT 2007


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!

> 2) when using
> multi-dimensional dynamic arrays, there are more casts

int[1000][] a;
...
a[3][4] = 2;

involves no casts.


> 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][]

> 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].




More information about the Digitalmars-d mailing list