Feedback Wanted on Homegrown @nogc WriteLn Alternative

via Digitalmars-d digitalmars-d at puremagic.com
Fri Oct 3 01:34:25 PDT 2014


On Friday, 3 October 2014 at 01:57:37 UTC, H. S. Teoh via 
Digitalmars-d wrote:
> The idea being that a call like `formattedWrite("%d", n)` is 
> far more
> likely to be reused in other places in the program, than the 
> specific
> format string "You have %d items in mailbox %s" and that 
> specific
> combination of parameter types (int, string). So even though 
> this does
> incur some template bloat, it will hopefully break down the 
> template
> instantiations into smaller chunks that are frequently reused.

Maybe you could do this as some kind of implicit range of 
"formatting references" so that you can iterate over it in two 
passes and save a heap allocation for situations where traversal 
is cheap (fits in level 1 cache):

1. first pass: collect max buffer size
2. alloca buffer on stack
3. second pass: format into buffer

?


More information about the Digitalmars-d mailing list