Fast way to update grids
David Collier-Brown
daveb at geac.UUCP
Sat Feb 6 00:10:15 AEST 1988
In article <690005 at hpfelg.HP.COM> jk at hpfelg.HP.COM (John Kessenich) writes:
> Use an array (it is the fastest know data structure for linear
> traversal in an arbitrary direction), but take advantage of C's
> pointer arithmetic. Example:
[elided]
> If you are going through the array in some order, the address step
> may not even be necessary.
> Also, for addressing, subscript ranges equal to powers of two will
> yield faster results. Why? They are compiled as << instead of *.
>
This is true for compilers using real multiplicative indexing. As
the white book is written to allow edge-vector addressing, and at
least one pcc-based compiler uses it, this turns out to be
compiler-dependent.
As it happens, the Waterloo (GCOS) C compiler uses edge-vectors, but
also (if memory serves) keeps the pointed-at data contiguous to
allow such assumptions to work nevertheless. Something of a ``best
of both worlds'' effect, at no extra cost to the program/programmer.
--dave (I was the bug-fix guy at the acceptor site) c-b
--
David Collier-Brown. {mnetor yunexus utgpu}!geac!daveb
Geac Computers International Inc., | Computer Science loses its
350 Steelcase Road,Markham, Ontario, | memory (if not its mind)
CANADA, L3R 1B3 (416) 475-0525 x3279 | every 6 months.
More information about the Comp.lang.c
mailing list