|
 |
On Sat, 10 May 2008 19:44:53 +0200, Darren New <dne### [at] san rr com> wrote:
> In any case, what *I* meant was that you get a new blob of code compiled
> every time you instantiate a template. Not for each different type, but
> even for the same types in different compilation units. Yes? Or am I
> confused about that? If I have std:vector<MyType> having functions
> called in one module, then I compile another module with
> std:vector<MyType>, does the linker see that it's the same code and
> function on the same type and only include one copy of the object code
> in the linked result?
Some compilers delay code generation of some templates until link time.
Even in the absence of delayed code generation, the linker merges
duplicates.
>> Thus any argument that
>> templates cause memory bloat is usually false. (Yes, there may be a few
>> situations where templated code causes more memory usage, but normally
>> it's the opposite.)
>
> I think they likely cause code file bloat. If you use the same template
> and instantiate it on 10 different types of pointers, aren't you going
> to get ten different copies of object code?
Some linkers can recognise that the generated code is identical, and merge
all the copies.
--
FE
Post a reply to this message
|
 |