www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - D2.x writef et al and template bloat

reply Bill Baxter <dnewsgroup billbaxter.com> writes:
It seems like writef and many other functions got changed to vararg 
templates in D2.x.

Doesn't this mean there will be a different instantiation of the writef 
template for every combination of arguments used to call it?  Sounds 
like it could lead to a lot of template bloat in D executables.  Is it a 
non-issue for some reason?

--bb
Oct 16 2007
parent reply Walter Bright <newshound1 digitalmars.com> writes:
Bill Baxter wrote:
 It seems like writef and many other functions got changed to vararg 
 templates in D2.x.
Yes. That makes them run much faster. Instead of interpreting the format at runtime, each format gets custom code.
 Doesn't this mean there will be a different instantiation of the writef 
 template for every combination of arguments used to call it?
Yes - but I'll correct that for every *type* combination of arguments.
 Sounds like it could lead to a lot of template bloat in D executables.  Is it
a 
 non-issue for some reason?
The linker will remove duplicates. However, I think even in a large program, there won't be that many combinations. It also has the potential to *reduce* code bloat in small programs, as the unused formatting code won't be there.
Oct 16 2007
parent BCS <ao pathlink.com> writes:
Reply to Walter,

 Bill Baxter wrote:
 
 It seems like writef and many other functions got changed to vararg
 templates in D2.x.
 
Yes. That makes them run much faster. Instead of interpreting the format at runtime, each format gets custom code.
 Doesn't this mean there will be a different instantiation of the
 writef template for every combination of arguments used to call it?
 
Yes - but I'll correct that for every *type* combination of arguments.
 Sounds like it could lead to a lot of template bloat in D
 executables.  Is it a non-issue for some reason?
 
The linker will remove duplicates. However, I think even in a large program, there won't be that many combinations. It also has the potential to *reduce* code bloat in small programs, as the unused formatting code won't be there.
If you want to known how many cases there are you can add a pragma(msg, formatTypeTupleTemplateWidgit!(args)) to wrightf and then filter the output for unique lines.
Oct 16 2007