473,387 Members | 1,603 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,387 software developers and data experts.

Best STL container to use for single pass-through operations

Quick question:

If I'm creating a container in logical order (1st node added, 2nd node
added, etc) and only reading in a single forward passthrough, what STL
container would be best optimized for this?

Thanks,
Josh McFarlane

Dec 6 '05 #1
4 1640
Josh Mcfarlane wrote:
Quick question:

If I'm creating a container in logical order (1st node added, 2nd node
added, etc) and only reading in a single forward passthrough, what STL
container would be best optimized for this?


std::deque, probably.

V
Dec 6 '05 #2
Josh Mcfarlane wrote:
Quick question:

If I'm creating a container in logical order (1st node added, 2nd node
added, etc) and only reading in a single forward passthrough, what STL
container would be best optimized for this?

Thanks,
Josh McFarlane


std::vector would be the default choice.
Dec 6 '05 #3
I'd go with a std::list.
If you know how many elements you have from the begining than
std::vector can be a good option, since all memory would be
preallocated and the element access would be in a constant time.
If thats not the case, then i'd stick with a list, since vectors would
add some resizing overhead, when you add one element more than their
capacity.

Dec 6 '05 #4

Augusto KhaoticMind da Silva wrote:
I'd go with a std::list.
If you know how many elements you have from the begining than
std::vector can be a good option, since all memory would be
preallocated and the element access would be in a constant time.
If thats not the case, then i'd stick with a list, since vectors would
add some resizing overhead, when you add one element more than their
capacity.


std::list should be your last choice. In general, it gives you the
worse access performance.

std::vector should be your default and preferred container to use, if
you're only adding and removing from the end of the container.

If you're adding and removing from the beginning and from the end of
the container, then use std::deque.

Only use std::list if you're adding and removing from the center of the
container.
Moreover, even if you're adding and removing from the center of the
container, experts like Herb Sutter, still recommend to consider using
std::vector if you're only infrequently adding/removing from/to the
center.

Dec 7 '05 #5

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

Similar topics

35
by: Swartz | last post by:
Hi all. I'm working here on a small project of mine. I'm not new to programming, but I'm new to PHP. You have to understand that I'm coming from C++, OOP world, so my code might seems a little...
0
by: Shaun Marshall | last post by:
Hope someone can help, for an assignment i was given a starter application package, with that starter package i had to create some employee classes and test harnesses. below iv pasted my Container...
3
by: RubiconXing | last post by:
Hi All Beginner question - please be patient with me :-) I am new to c#. If one creates a child modal (and also non-modal) form what is the best way of returning the collected data back to the...
3
by: Ed | last post by:
Hi, I have a WorkUnit class. I will pass a reference to a group of these WorkUnits to other classes in my application. I have chosen to use a vector to hold pointers to these WorkUnits for now....
10
by: Sean C. | last post by:
Helpful folks, I ran across a statement I found rather confusing in the IBM-published Advanced DBA Certification Guide and Reference for UDB V8. On page 107 the author is explaining why the a...
3
by: jignesh shah | last post by:
Hi all, Is there a way to recover a single container if its been corrupted or mark bad without restoring whole tablespace? environment: db28.1/aix5.1/tsm/rs-6000. Regards Jignesh
1
by: Chris Fink | last post by:
Hi, My question is how do I set some text within my datalist itemtemplate to be bold, based on the higher value of two bound data items? For example, if the value of <%#...
2
by: Anil Pundhir | last post by:
What is the best way to pass data to a web service. The client(to send data) has .net environment and also the server on which the web service is hosted also has the .net environment. Should I...
4
by: Michel Esber | last post by:
Hello, LUW V8 FP 11 running Linux RH AS4 Update 3. In regards to performance and IO parallelism, does it matter if I create a tablespace with a single big container, or is it better to create...
36
by: Peter Olcott | last post by:
So far the only way that I found to do this was by making a single global instance of the container class and providing access to the contained class, through this single global instance. Are...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.