How are 2D static arrays allocated?
Lars Kyllingstad
public at kyllingen.NOSPAMnet
Wed Nov 5 02:48:50 PST 2008
Lars Kyllingstad wrote:
> Jarrett Billingsley wrote:
>> Performance of dynamic arrays is the same no matter where their data
>> is. Fixed-size 2D arrays are not faster _because_ they are on the
>> stack, they just happen to be allocated on the stack. They are faster
>> (usually) because they don't need two pointer dereferences. You can
>> allocated a fixed-size 2D array on the heap (well.. inside a struct or
>> class anyway) and it will be just as fast.
>
> Your "usually" interests me. I was under the impression, and it seems
> quite logical, that static arrays are faster than dynamic ones. However,
> recently I did some simple experiments with matrix operations
> (multiplication, etc.), in which performance was actually a little bit
> better for dynamic arrays.
>
> Is there a general "rule" for when dynamic arrays are faster than static
> ones, and vice versa?
>
> Also, I tried multiplying large matrices both using arrays in D and
> using a C BLAS implementation. The BLAS algorithm is the same as the one
> I've written in D, and additionally includes a lot of runtime checks.
> Still, multiplication using BLAS was about four times faster. Is this
> simply because C compilers are a lot better at optimisation than the D
> compilers?
I just remembered that D also does bounds checking on arrays. To work
around this, I tried accessing the array elements through pointers. To
my surprise, this actually didn't affect the results very much.
Therefore my question still stands.
-Lars
More information about the Digitalmars-d-learn
mailing list