![]() |
|
|
|
#11 |
|
Originally posted by Sean Dettrick > Michael Aramini <> wrote in message > news:<SeS4b.16820$>. .. > > > > For 1D arrays, the choices are: > > valarray<type> vs. vector<type> > > > > For 2D arrays, the choices are: > > valarray< valarray<type> > vs. valarray< vector<type> > > vs. > > vector< valarray<type> > vs. vector < vector<type> > > > > > If speeds is of the essence, I would suggest you measure the times > yourself. > Also consider building classes so that the underlying STL class > (vector, valarray, deque) can be changed without effecting the rest of > your code. > > For 2D and 3D arrays, I have found it is faster to use a 1D > vector<double> with a computed index (kept track of manually) than to > use vector < vector<type> > or > vector < vector< vector<type> > >. In the 3D case, a 1D vector is > MUCH faster than a 3D vector. In the 2D case, the speed difference > was about 10% I think. > > Question: Instead of using a vector<vector<type>> for a 2d array, > we can also use vector<anothertype>, where "anothertype" has two > members of "type". > > My question: Is this way of implementation is more efficient then > having a long vector of 1d with a computed index in order to manage 2d > vector?. > > Quick replies for this question will be very useful to me. Thanks in > advance. > > -Vijaya. > > > In my application, type is will be a scalar type such as bool, > double, > > int, or size_t. > > Then you need to read about the well known caveat about vector<bool> > (e.g. in the Meyers book), and consider using deque<bool> for the bool > case. > > > The code is initially being targeted for Linux, but it may also > be > > ported to another UNIX such as IRIX, or perhaps even Windows, so > I'd > > like to keep things portable by using an STL container rather > than one > > from some operating system specific template library. > > Sounds like you'll be using a lot of different compilers - beware that > valarray is not always well supported. I found vector and valarray > had the same speed, but valarray wasn't fully supported by all > compilers. > > Finally, if you ever plan to interface to legacy C or fortran code, a > 1D vector<> has the advantage that its contents are guaranteed to be > contiguous in memory. That simplifies any such interface > considerably. > Sean -- Posted via http://dbforums.com vrambati |
|
|