|
![](/i/fill.gif) |
Darren New <dne### [at] san rr com> wrote:
> Warp wrote:
> > Let's take a better example: Every time I want to use std::vector,
> > I have to #include <vector> in the source file where I want to do so.
> Or, to phrase it differently:
> vector.hpp is a standard file from the standard library. Why the hell are
> you compiling it, over and over, every time you compile your program?
The advantage is that the end result is much more efficient (both
speedwise and memorywise) because it allows the compiler to perform
heavy-duty optimizations on the included code based on the types you are
using as well as many other things. (Of course that's not the *original*
reason to have include files, but it's a nice side-effect of them that
makes them actually quite useful.)
(Curiously, the next C++ standard will include a feature called "extern
template" which allows you to defer the compiling of the templated code
into one single compilation unit. This doesn't have efficiency advantages,
but it can speed up compilation and make object files smaller. It's still
not the same thing as an "export template" though, and shouldn't be confused
with it.)
> Doesn't it strike you as a bit odd that standard libraries that come with
> the compiler still get compiled on your CPU over and over?
Not for templated code, no. As for non-templated code, they usually come
in precompiled dynamically loadable versions (or statically linkable, if
you want).
--
- Warp
Post a reply to this message
|
![](/i/fill.gif) |