<div dir="ltr">On 12 April 2013 23:21, 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">On Friday, 12 April 2013 at 07:04:23 UTC, Manu wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
string[string] is used in the main API to receive environment variables;<br>
perhaps kinda convenient, but it's impossible to supply environment<br>
variables with loads of allocations.<br>
</blockquote>
<br>
Environment variables are a mapping of strings to strings.  The natural way to express such a mapping in D is with a string[string].  It shouldn't be necessary to allocate an AA literal, though.<br></blockquote><div>
<br></div><div style>That's a good point, do AA's support literals that don't allocate? You can't even produce an array literal without it needlessly allocating.</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
toStringz is used liberally; alternatively, alloca() could allocate the<br>
c-string's on the stack and zero terminate them there, passing a pointer to<br>
the stack string to the OS functions.<br>
</blockquote>
<br>
It is kind of hard to use alloca() in a safe manner in D, because DMD will happily inline functions that use it.  The following program will overflow the stack if compiled with -inline:<br>
<br>
void doStuff()<br>
{<br>
    auto p = alloca(100);<br>
}<br>
<br>
void main()<br>
{<br>
    foreach (i; 0 .. 1_000_000) doStuff();<br>
}<br>
<br>
This is of course fixable, but until that happens, I would consider alloca() a no-go for Phobos.<br>
</blockquote></div><br></div><div class="gmail_extra" style>Very good point. This is a problem.</div><div class="gmail_extra" style>Hmmm...</div></div>