First of all, I just want to clearify that STL is so much more than just the vector container.
Choosing the right container for your application is also something one should consider.
Since this discussion has started I got curious and used the all-knowing Google to find benchmark results for built-in array vs. STL vector and I found these two links.
http://www.cs.duke.edu/~ola/courses/cps ... e/builtin/
http://www.opencascade.org/upload/87/gc ... ean_marker
Both are tests executed on rather powerfull computers (atleast compared to a PDA) so I'm not shure how useful these results are. But they both show that regular array usage has faster access times than using the STL vector container (as I hinted before).
The second link goes to a benchmark that I won't even begin to try and explain here because the note would be loooooooooooooooong (or perhaps I should say looooooooooooooooooonger! ;).
The first link however goes to a test that got the following results:
a_int = 0.47
v_int = 0.58
a_str = 1.18
v_str = 1.36
a_strp = 0.44
v_strp = 0.58
a_cstr = 0.44
v_cstr = 0.6
where
a = built-in array allocated with new.
v = STL vector
int = integer
str = STL string
strp = STL string pointer
cstr = CString / char*
The result is the time in seconds it took to perform the test on a "Sun Ultrasparc 20 with 128 megabytes of memory"
The tests was 10 repetitions of an array of 100,000 elements that was first copied to another array and then shifted to the right so that the last element became the first. So, each test is 10*100000*4=4M array/vector element accesses (2 gets and 2 puts for each element)
Pew.. for more info I refer to the above link. Unfortunately I ran into some problems when I tried to convert the test so it could be run on a PDA platform and I don't have time for this right now (this took long enough, let me tell you).
Hope someone finds this usefull.. And perhapps someone can make a WinCE port of the test so we can test our own devices.
I still stand by my previous notes though. STL containers should be used where applicable. Arrays should be used instead of STL vectors when access time is crucial. And I mean CRUCIAL! If you take a look at the test, it says that for 4M element accesses the maximum time penalty is 0.18 seconds. These test results has not been (as far as I could understand anyways) averaged over a series of tests so the average maximum time penalty is probably a few hundreds of a second lower.
Accessing only a few hundred elements and I would assume that the time differance would be very slim (or practicly zero as Thierry said).
But, it remains to be seen how the test preforms on a PDA.
Benefits of using STL containers are:
* They are dynamic.
* They are thuroughly debugged and tested.
* You don't have to keep track of the number of elements in the container, since all containers have a size() or length() function.
* You won't run into memmory leaks since each container is allocated on the stack and will be deallocated once it goes out of scope (like any other local variable). This ofcourse asumes that you don't store any heap allocated data (i.e. with new) in the containers, because then you are responsible for deallocating it as usual (with delete).
* The containers are very similar so if you need to change to a different representation it wouldn't take that much of an effort (relatively speaking anyways).
* All the containers can be accessed through iterators, which allows you to write code independant of the chosen container which could be practical in some situations.
I'm shure there are a few more but I'm to damn tired to come up with them.
Thank you and good night =)