473,321 Members | 1,708 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,321 software developers and data experts.

vector, list and deque

al
When should pick vector, over list or deque to use? Thanks!
Jul 22 '05 #1
4 2546
al wrote:
When should pick vector, over list or deque to use? Thanks!

When you need random access to the elements of the collection, and you
will be doing insertions and deletions only at the back of the container.

Jul 22 '05 #2

"Jeff Schwab" <je******@comcast.net> wrote in message
news:MY********************@comcast.com...
al wrote:
When should pick vector, over list or deque to use? Thanks!

When you need random access to the elements of the collection, and you
will be doing insertions and deletions only at the back of the container.


That is when you NEED to pick vector.
You SHOULD pick vector whenever you DON'T need to insert/delete in the
middle (list) or insert/delete from the front (deque).
Also the one thing that vector gives you over the others regardless of
performance issues is a pointer to a contiguous array.
Jul 22 '05 #3
Nick Hounsome wrote:
"Jeff Schwab" <je******@comcast.net> wrote in message
news:MY********************@comcast.com...
al wrote:
When should pick vector, over list or deque to use? Thanks!

When you need random access to the elements of the collection, and you
will be doing insertions and deletions only at the back of the container.

That is when you NEED to pick vector.
You SHOULD pick vector whenever you DON'T need to insert/delete in the
middle (list) or insert/delete from the front (deque).


Knowledge that a container will not be used for certain things is not
enough to tell what sort of container is needed. A fixed-size amount of
data available at compile-time might best be placed in a static array.
Also the one thing that vector gives you over the others regardless of
performance issues is a pointer to a contiguous array.


No; your implementation might, but the standard does not. GCC uses a
class template called "normal_iterator."

Jul 22 '05 #4
Jeff Schwab wrote in news:c9********************@comcast.com:
Also the one thing that vector gives you over the others regardless of
performance issues is a pointer to a contiguous array.


No; your implementation might, but the standard does not. GCC uses a
class template called "normal_iterator."


std::vector< T > vect;

// insert some T's ...

&vect[0] (and &*vect.begin()), is guaranteed to be pointer to a
contiguous array.

This is an update (2003) to the original (1998) standard.

Rob.
--
http://www.victim-prime.dsl.pipex.com/
Jul 22 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

29
by: Hagen | last post by:
Hello, in a recent thread "speed of vector vs array" I read about the problem of the slow acces by addressing vector elements by indexing, unfortunately I see no workaround in my case. My...
11
by: Richard Thompson | last post by:
I've got a memory overwrite problem, and it looks as if a vector has been moved, even though I haven't inserted or deleted any elements in it. Is this possible? In other words, are there any...
34
by: Adam Hartshorne | last post by:
Hi All, I have the following problem, and I would be extremely grateful if somebody would be kind enough to suggest an efficient solution to it. I create an instance of a Class A, and...
5
by: yancheng.cheok | last post by:
after reading http://www.codeproject.com/vcpp/stl/vector_vs_deque.asp, i realize that deque has its own speed advantage over vector in all the aspect (except for memory deallocation). does it...
9
by: Ian | last post by:
I would like to port my class library written in standard C++ with STL to C++/CLI. Several of my classes inherit from std::vector or std::deque. From what I can see, dot.net does not offer...
2
by: Thormod Johansen | last post by:
Hi, I have just read the article about iterators at http://www.oreillynet.com/pub/a/network/2005/10/18/what-is-iterator-in-c-plus-plus.html?page=last and I am wondering about what is ment by the...
32
by: T. Crane | last post by:
Hi, I'm struggling with how to initialize a vector<vector<double>> object. I'm pulling data out of a file and storing it in the vector<vector<double>object. Because any given file will have a...
1
by: subramanian100in | last post by:
Suppose I have vector<intvi; deque<intdi; list<intli; Suppose all of these containers have some elements. Suppose 'v_iter' is an iterator pointing to some element in 'vi'. Suppose 'v_beg'...
4
by: alexjcollins | last post by:
The following program demonstrates the problem: #include <vector> #include <iostream> #include <tvmet/Vector.h> typedef tvmet::Vector<double, 3Vector3d; class Mesh {
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.