Re: Which STL should I use?
"Jacky Luk" wrote:
In this situation, which STL component should be used?
Two corrections. STL is an old name that stands for
"Standard Template Library". Many people still use it,
however, the correct term is "Standard C++ Library". Also,
the correct term is "container", not "component". Standard
C++ Library can be divided into four major logical parts:
0. C Runtime Library. The legacy inherited from C
language. It contains functions like "fopen" and "printf".
1. Containers and iterators. This part comprises of
classes, which allow to store user defined objects in
collections. Examples: std::vector, std::list, std::map.
Various iterator classes allow to manipulate content of
containers.
2. Algorithms. This part contains useful implementations
of popular algorithms. These algorithms work on containers
using iterators. Examples: std::copy, std::find, std::count.
3. Streams. This part was standalone addition to STL
until recently. Now streams are part of Standard C++
Library. Streams allow to perform input/output operations.
Examples: std::ofstream, std::strstream.
Here's entry point for Standard C++ Library in MSDN:
"Standard C++ Library Reference"
http://msdn2.microsoft.com/en-us/library/cscc687y(VS.80).aspx
1) add/update records quite frequently, but only when the
program initializes.
Not enough information. std::list allows fast
addition/removal of elements but slow random access to an
element. std::vector provides fast access to an element but
slow addition/removal (especially in the middle and
beginning of container). std::deque tries to take best of
both worlds providing relatively fast access to an element
and addition/removal from/to ends of container.
2) need to compare values with older records, almost
always
It depends on an object. If contained object is trivial,
then sometimes simple call to memcmp on two vectors will do
the job. With other containers you will need to compare each
element with the other.
3) need direct access all the time
Fast random access is the advantage of std::vector and
std::deque containers.
I have been struggling with lists and maps?
Or there is a better solution?
What are criterions of better solution? Access speed? Memory
layout? Other?
HTH
Alex