Mental wrote:Also, as far as the STL goes, the reason I'm a little squeamish about code size is that, as far as I know, it *does* get added to your binary - all of it. You can't just compile in, say, the one structure you need or plan to use.
I'm confident that's not true - it runs contrary to my understanding of how templates work and contrary to the design principles of C++.
Simply, templates are not compiled unless they're used (or explicitly instantiated, but you won't do that on accident). They're always lexically parsed, but they only go through the code generation phase if they're used. You can see an example of this by writing a syntactically correct template class or function, but which contains some compile time error (type errors are the easiest to contrive). If you don't call the function or use the class, the compiler won't complain. If it's not compiled, it certainly isn't going in the binary.
Further, even if you use a particular templated class, but don't use one of its member functions, that member function isn't compiled either.
There's also no way for "all" of the STL to be included if you only say <TT>#include <vector></TT>. There's no way (let alone reason) for the compiler to see <TT>map</TT>s or <TT>list</TT>s. However, when you <TT>#include <vector></TT> that will likely depend on some base definitions that are implementation dependent, and some standard C routines and definitions. But a good optimizing compiler can remove layers of abstraction.
When Stroustrup deisgned C++, one of the design principles he used was that you don't pay for what you don't use. If you don't use virtual functions, you don't pay for them. If you don't use inheritence, you don't pay for it. And certainly, if you don't use a class or a function, you don't pay for it. So, yes, you can selectively use whatever you want from the STL. But, there is a possibility that what you want to use depends on more than you realize, so always measure before coming to a conclusion.
You might be interested in reading the <a href="
http://www.research.att.com/~bs/perform ... >Technical Report on C++ Performance</a> that was put out by the ISO C++ committee in response to the same concerns you've voiced about C++ in embedded environments. It's an interesting read. They also explicity state what's <i>not</i> good to use in an embedded environment: <TT>std::string</TT> and all of the stream classes, for example.
Mental wrote:I don't know if a modern optimizing compiler/linker might optimize out the unused function calls in the final binary, but I haven't really needed to try to find out, since the abstract collection class I've implemented seems to be working fine so far, and I know firsthand how tiny it is (about 300 lines of code all told, including comments.)
Simplicity of implementation does not always translate to more effecient code. I've implemented my own lists and queues that only do exactly what I need them to do, and the STL versions beat mine every time. But, I work in an environment where speed is the most important metric. Code size isn't an issue.