Garbage collection, and practical strategies to avoid allocation

Brad Anderson eco at gnuk.net
Fri May 31 19:47:39 PDT 2013


On Saturday, 1 June 2013 at 02:16:02 UTC, Adam D. Ruppe wrote:
> just to toss in my quick thoughts, I wrote a couple comments on 
> the recent reddit thread about using D with a minimal runtime 
> and some of the talk may be relevant here too:
>
> http://www.reddit.com/r/programming/comments/1fc9jt/dmd_2063_the_d_programming_language_reference/ca94mek
>
>
> Some little things we could do is add overloads to some 
> functions that return string to be able to take a buffer 
> argument too.
>
> string to(T:string)(int a) { char[] buf = new char[](16); 
> return assumeUnique(to(a, buffer));
>
> char[] to(int a, char[] buffer) { deposit it straight into 
> buffer, return the slice into buffer that is actually used; }

I played around with adding an overload that accepted an output 
range to some of the std.string functions identified in my run of 
-vgc over phobos[1] (after Jonathan pointed out this is probably 
the best approach and is already what formattedWrite does).  It 
worked fine but it did make me realize there aren't a lot of 
output ranges available to plug in at the moment (appender and 
lockingTextWriter are the only two that come to mind though there 
may be others).  Appender isn't useful if your goal is to avoid 
the GC.  Array!char et al aren't output ranges (whether they 
should be or not I have no idea).  static arrays would need some 
sort of wrapper to make them output ranges I believe unless it 
was decided that put() should work by replacing the front and 
calling popFront for them (which I kind of doubt is the desired 
behavior).

(feel free to correct me on any of this, range experts)

1. http://goo.gl/HP78r


More information about the Digitalmars-d mailing list