Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Core » what technique does U++ use to reduce code bloat from too many template instantiations?
what technique does U++ use to reduce code bloat from too many template instantiations? [message #410] Mon, 12 December 2005 21:02 Go to next message
fudadmin is currently offline  fudadmin
Messages: 1321
Registered: November 2005
Location: Kaunas, Lithuania
Ultimate Contributor
Administrator
what technique does U++ use to reduce code bloat from too many template instantiations?
Re: what technique does U++ use to reduce code bloat from too many template instantiations? [message #411 is a reply to message #410] Mon, 12 December 2005 21:44 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
fudadmin wrote on Mon, 12 December 2005 15:02

what technique does U++ use to reduce code bloat from too many template instantiations?



A good question Smile Actually, some of that is reduced by smart linkers (they are able to merge the same function).

Anyway, the really great reduction is result of U++ containers, esp. two things: Array container has really low footprint (it needs about 200 bytes pre instantiation) and Map containers are composites of Index and Array or Vector, with quite a lot Index hashing code implemented in non-template .cpp.

To explain composition issue: VectorMap<String, int> and VectorMap<String, String> are actually compostions of Index<String> and either Vector<int> and Vector<String> and "composition" code is really minimal. Compare with STL that generates totally different code for map<string, int>, map<string, string>, vector<string> and vector<int>. With more types involved, advantage on U++ side increases....
Re: what technique does U++ use to reduce code bloat from too many template instantiations? [message #5204 is a reply to message #410] Sun, 10 September 2006 18:32 Go to previous messageGo to next message
thierry is currently offline  thierry
Messages: 9
Registered: September 2006
Promising Member
Could it possible that theIDE can help still a little with encouraging the following practice in case of not so clever linker (relying only on weakreferences) that anyway can't avoid the inline code bloat:

T.h : no inline code for templates
(well just recommand and do it)

T.tpp: template function implementation

T_mytype.cpp: one for each explicit instanciation
#include "T.tpp"
template T<mytype>;

This is really annoying for a programmer to create one cpp per instanciation, but this is where an ide can help a lot to save developer to follow this guideline with generating the T_mytype.cpp for him, with maybe having a repository of all instanciations at least by packages... Then the linker shall be only smart enough not to link twice the same code.

This would not only save code bloat, but also compilation time, so far template would be compile only once, and changes in .tpp won't affect other modules



Re: what technique does U++ use to reduce code bloat from too many template instantiations? [message #5208 is a reply to message #5204] Sun, 10 September 2006 18:59 Go to previous message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Hm, I am not sure there are toolchains able to compile U++ (which itself is in fact limited to gcc 3.1+ or msc 7.1+ or EDG frontends) and not support this kind of optimization.

Mirek
Previous Topic: Proposal: BinFindIndex should return 0 for empty container
Next Topic: Value with unsigned support
Goto Forum:
  


Current Time: Sat Apr 27 17:11:16 CEST 2024

Total time taken to generate the page: 0.04936 seconds