[A89] Re: Multi-dimensional Arrays in C...


[Prev][Next][Index][Thread]

[A89] Re: Multi-dimensional Arrays in C...




> Usually, multiple-pointer method is not slow. It is maybe even
> faster, because this method internally uses extra indirection
> instead of multiplication (and multiplying is usually slower).
> But, multiple-pointer method uses more memory (to store extra
> pointers to each row of a matrix).

FYI, I've found that the multiple-pointer method (that is, arrays of arrays)
being discussed here is technically called a "ragged array."  One of the
(few?) neat things about Microsoft's C# proposal is that it actually has two
multidimensional array formats, one that uses contiguous memory and
multiplication and another than uses these ragged arrays.

As for the internal multiplication slowdown, I've read that you can avoid
much of this if all but the first dimension has a size that is a power of
two.  This way, shifting and addition can be used instead of multiplication
internally.  In other words, if you want an array of size 3x7, you can often
speed up access by making it 3x8 and ignoring the 8th column.

    -Scott