POV-Ray : Newsgroups : povray.off-topic : A question about Java generics (not a flame) : Re: A question about Java generics (not a flame) Server Time
7 Sep 2024 19:17:22 EDT (-0400)
  Re: A question about Java generics (not a flame)  
From: Fredrik Eriksson
Date: 10 May 2008 14:32:03
Message: <op.uaya3o1d7bxctx@e6600.bredbandsbolaget.se>
On Sat, 10 May 2008 19:44:53 +0200, Darren New <dne### [at] sanrrcom> 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

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.