Go Back   Velocity Reviews > Newsgroups > C++
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

C++ - C++ STL valarrays vs. vectors

 
Thread Tools Search this Thread
Old 11-03-2003, 11:15 AM   #11
Default Re: C++ STL valarrays vs. vectors



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
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46