Re: OONSTD: Element Ordering 2D Arrays

Theodore Papadopoulo (Theodore.Papadopoulo@sophia.inria.fr)
Thu, 09 Jul 1998 18:46:04 +0200

> > If you are concerned with efficiency (I am) add one precomputed M-length
> > vector of pointers (at timeof construction) to avoid any runtime overhead.
>
> Wouldn't the extra memory access take far longer than a multiply?
> Especially since the array pointer and N would be adjacent in memory
> (since they are in the same object) while the vector of pointers would be
> dynamically allocated?

This is something that I have heard many times without ever
being really convinced. To me multiplication takes (well at least two
or three years ago) at least four clock cycles whereas addition or
memory accesses take 1. This is/was quite general.

Of course, this is true only if the memory block is in the cache but
one could expect this to be true as the vector of pointers will be
accessed each time a array element is read or written.

On the other hand, I have seen an argument about aliasing problems
introduced by the vector of pointer technique that was reasonnably
convincing even thought I'm not quite sure that if it is related to
compilers or to the standard for C and C++ (for example egcs alias
analysis improved quite a lot recently at the only cost of forbidding
thing like * (int *) &d = 1234; where d is a double).

Obviously this may vary with compilers and processors...

Does anyone have more insight in the problem ?

Sorry, all this is slightly out of the topic of the mailing list...

Theo.

--------------------------------------------------------------------
Theodore Papadopoulo
Email: Theodore.Papadopoulo@sophia.inria.fr Tel: (33) 04 92 38 76 01
--------------------------------------------------------------------