Effective STL 1: Choose your containers with care @ 5/19/2006

programming & research
Contiguous-memory containers:
  rope (heavy-duty string)
Node-based containers:
  all the others (list, map, hash_map,...)

So, if you need few add/remove operations and many random access, you better use vector or deque, string or rope.
Also, if you have a vector v, you can get the underlying array by &v[0]. This is very useful when you are writing C++ code which can be used in C (for C doesn't know any vector, it only knows array).

The difference between vector and deque (pronounced as 'deck') is that you can only insert into the back of a vector, while insertation into both front and back of a deque is allowed.

hash_map is not in STL, but you can find it in almost every implementation of C++ compiler.
发布于 5/19/2006 20:40:13 | 评论:0