On 2010-12-19 15:17:50 -0500, Jacob Carlborg <d...@me.com> said:
On 2010-12-19 19:29, Michel Fortin wrote:
Has anyone checked which of delegates or strings cause more template bloat?
I'd suspect using strings will result in less bloat because the same
string will often be reused (making the compiler reuse the same template
instance) whereas the compiler will likely use the mangled name of the
delegate when instantiating the template... and no two delegate literals
have the same mangled name.
That would only be the case if the function takes the delegate as a
template parameter?
Indeed. Passing a delegate as a function argument won't create a new
instance of that function.
This is also why it runs slower: the function doesn't know which
delegate is called until runtime. If the function is short, it could be
inlined, which would in turn allow the delegate to be inlined and run
faster. But if you somehow could force the compiler to inline 'sort'
all the time it's likely the code bloat will be even worse.
--
Michel Fortin
michel.for...@michelf.com
http://michelf.com/