easier way?

bearophile bearophileHUGS at lycos.com
Wed Aug 25 18:50:47 PDT 2010


Jason Spencer:
> Knowing just the # of dimensions won't tell me
> the total size or how to index.  I need the size of each dimension.

If you create such structs, you do what you want, so it represents a nD rectangular array. The total size is computed by the product of n runtime values stored inside the struct itself. And the indexing is not a problem, but you need n-1 run-time multiplications to find your index, unless you impose the constraint your sizes are a power of two, so you can replace the multiplications with shifts, that sometimes may give a small performance gain.

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list