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

.



Relevant Pages

  • Re: Tuna fish
    ... It has been at least a year since I've purchased tuna. ... The cans have ... (i also only just recently noticed the rectangular plastic lidded containers ... standard package sizes, to be accompanied by howls of rage by the ...
    (rec.crafts.metalworking)
  • Re: Newbie question :) be kind...
    ... measuring system as a thing in itself, ... Consider the standard intermodal shipping containers. ... I liased with New Zealad Railways to move containers around the country. ... Most tunnels would clear the ...
    (rec.models.railroad)
  • Re: Identifying potions from memory
    ... The modern world comes with labels because the containers are all standardised and repeatedly purchased with the product. ... Same for potions, really. ... you'd find it even more likely that there might not be a standard labelling system. ...
    (rec.games.frp.dnd)
  • Re: Forth and Unix -- history
    ... However, members of the TC had recent or current experience with processors with 4-bit AUs and 16-bit AUs, not to mention 32-bit characters. ... Forth provides handlers for containers of whatever size is useful on a particular architecture, but does not attempt to prescribe the nature of the content of those containers. ... But here's a case where Standard Forth is very irregular, ...
    (comp.lang.forth)
  • Re: Which STL should I use?
    ... STL is an old name that stands for "Standard Template ... Containers and iterators. ... This part was standalone addition to STL until recently. ... providing relatively fast access to an element and addition/removal ...
    (microsoft.public.vc.language)