<div dir="ltr">On 12 April 2013 22:30, Lars T. Kyllingstad <span dir="ltr"><<a href="mailto:public@kyllingen.net" target="_blank">public@kyllingen.net</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">On Friday, 12 April 2013 at 11:37:14 UTC, Regan Heath wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I've moved this to another thread to allay complaints.<br>
</blockquote>
<br></div>
Thanks!<br>
<br>
I completely agree that if code can be made more performant without a significant increase in complexity, then we should do so.  While it is mostly (but not entirely) irrelevant in the context of std.process, it is a problem that should be tackled in Phobos as a whole.  Several things could/should be done:<br>

<br>
It would be nice to have some sugar on top of alloca(), the use of which is usually considered bad practice.  Someone (bearophile?) once suggested static arrays whose length is determined at runtime, which would be a great addition to the language:<br>

<br>
    void foo(int n)<br>
    {<br>
        int[n] myArr;<br>
        ...<br>
    }<br></blockquote><div><br></div><div style>That's beautiful!</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Furthermore, we need to get the allocator design in place.  In SciD, I use David Simcha's region allocator to allocate temporary workspace, and it works really well.  The only times I use 'new' is when I need persistent memory (e.g. for a return value) and the user-supplied buffer is too small.  Phobos would greatly benefit from doing this too.<br>

<br>
Finally, an example from the new std.process which got some heavy criticism in the other thread:<br>
<br>
    envz[pos++] = (var~'='~val~'\0').ptr;<br>
<br>
I have been operating under the assumption that the compiler is smart enough to make the above a single allocation.  If it isn't, I would consider it a compiler issue.<br></blockquote><div><br></div><div style>Does it? I've not seen the compiler do that, although I'd like to think it should be possible. 1 allocation is better than 3 I guess, however, I wonder if that code could be restructured to use the stack aswell.</div>
<div style>alloca() is really underrated! I can't imagine why people don't like it. Perhaps some more helpers built around it might encourage its use? It does feel a little bit 'raw', like malloc(). It implies some annoying casts.</div>
</div></div></div>