Containers.Item1 Choose your containers with care
amare小霸王 (Li Yingjun)
• The standard STL sequence containers, vector, string, deque, and list.
• The standard STL associative containers, set, multiset, map and multimap.
• The nonstandard sequence containers slist and rope. slist is a singly linked list, and rope is essentially a heavy-duty string.
• The nonstandard associative containers hash_set, hash_multiset, hash_map, and hash_multimap.
Contiguous-memory containers (also known as array-based containers] store their elements in one or more (dynamically allocated) chunks of memory, each chunk holding more than one container element. If a new element is inserted or an existing element is erased, other elements in the same memory chunk have to be shifted up ordown to make room for the new element or to fill the space formerly occupied by theerased element. This kind of movement affects both performance (see Items 5 and 14) and exception safety (as we'll soon see). The standard contiguous-memory containers are vector, string, and deque. The nonstandard rope is also a contiguous-memory container.
Node-based containers store only a single element per chunk of (dynamically allocated) memory. Insertion or erasure of a container element affects only pointers to nodes, not the contents of the nodes themselves, so element values need not be moved when something is inserted or erased. Containers representing linked lists, such as list and slist, are node-based, as are all the standard associative containers. typically implemented as balanced trees.)
说明 · · · · · ·
表示其中内容是对原文的摘抄