The former option had risks of increased development time and costs associated with it. Reducing such risks meant customizing the library to the application for which it was being developed, resulting in its incompatibility with other application that will be developed in the future.
The latter option although reduced the risks associated with the first option but introduced following further risks,
- Issues related to potential incompatibility with platforms, development environments and other libraries to which the software has to be linked,
- Future costs of upgrades. All programmers are well aware of incremental costs of software upgrades that offer more and/or improved features,
- Potential performance and extensibility issues related to the characteristics of implementation. For example, the use of virtual functions in internal objects can not only reduce the performance of the library but also make it difficult to use in a shared memory system. Algorithms in such libraries are usually implemented as class members thereby restricting change.
To overcome these issues, the ANSI (American National Standards Institute) decided to select STL as a standard set of collection classes and algorithms. STL is based on the successful research and development at Hewlett Packard Laboratories in the area of generic programming.
Typical features of STL are as follows,
- Efficiency. STL does not use inheritance or virtual functions.
- Type safety. The extensive use of C++ templates makes STL type safe.
- Consistency. STL container classes use iterators that are generalized pointers to the data contained within the containers. Iterators allow access of data within the containers in a manner similar to C arrays.
- Extensibility.
- STL algorithms are stand-alone functions that do not access STL containers directly. Rather they operate over the data via the iterators.
- STL allows the use of function objects. These are functions that can be encapsulated and associated with data. These can be created, stored and destroyed like objects.
- STL memory management does not explicitly use new and delete operators. STL containers use special allocator objects to allocate and deallocate storage. If an application requires different memory allocation and deallocation policies, these can be implemented using specialised allocator objects. These allocators can then replace the standard allocators in the containers to provide custom memory management. This article will, however, only consider the use of standard allocators.
STL Containers
STL containers can be divided into the following three categories,
- Sequential containers. These containers arrange the data they contain in a linear manner.
- Associative containers. These containers maintain data in structures suitable for fast associative look-up.
- Adapters. These provide different but more appropriate interfaces to containers belonging to the above-mentioned categories.
Specific containers belonging to each category are listed in the following table.
Category | Containers | Characteristics |
Sequential | vector | Provides a linear and contiguous storage (similar to an array) that allows fast inserts at the end only. |
list | It is an implementation of a doubly linked list that allows fast inserts anywhere. | |
deque | Provides a linear but non-contiguous storage that allows fast inserts at extremities. | |
Associative | multiset | It is an implementation of set where duplicates are allowed and provides fast associative lookup. |
set | It is an implementation of set where no duplicates are allowed and provides fast associative lookup. | |
multimap | It is an implementation of a key to value mapping structure where a single key can be mapped to many values (1 to many mappings). | |
map | It is an implementation of a key to value mapping structure where a single key can only be mapped to one value (1 to 1 mapping). | |
Adapter | stack | It is an implementation of a first in last out data structure. |
queue | It is an implementation of a first in first out data structure. | |
priority_queue | A queue that maintains items in a sorted order |
No comments:
Post a Comment