<div dir="ltr">On 12 April 2013 17:35, Steven Schveighoffer <span dir="ltr"><<a href="mailto:schveiguy@yahoo.com" target="_blank">schveiguy@yahoo.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div class="im">On Fri, 12 Apr 2013 03:04:08 -0400, Manu <<a href="mailto:turkeyman@gmail.com" target="_blank">turkeyman@gmail.com</a>> wrote:</div>
</blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div class="im">
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
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></div>
I think you meant "without"?<br></blockquote><div style><br></div><div style>Yes.</div><div style><br></div><div style><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">

What would be your suggestion?  string[string] is the built-in map type.  How do you pass an environment map without having some allocations?</blockquote><div><br></div><div style>I'd use string[].</div><div><br></div>
<div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div class="im">
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style: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></div>
This would be a lot of effort for pretty much zero gain for the majority of cases.</blockquote><div><br></div><div style>A trivial ... mixin template (?) could wrap it up, I don't see it particularly less convenient than calling toStringz().</div>
<div style>Perhaps there are other tools missing from phobos if this is somehow hard...</div><div><br></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div class="im">
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
String concatenation is rampant! Look at this code to parse the env<br>
variables (which are already an AA):<br>
<br>
    foreach (var, val; childEnv)<br>
        envz[pos++] = (var~'='~val~'\0').ptr;<br>
</blockquote>
<br></div>
This could be improved.  It could also be optimized into a single allocation automatically by the compiler (it might already be).  The API would not be affected by this improvement, though.<br></blockquote><div><br></div>
<div style>I've never seem the compiler apply that optimisation, although I often wish it would.</div><div style>I saw an appender appear a few pages below, that would be an improvement here too I guess. </div><div><br>
</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div class="im">
And many many more of the same...<br>
<br></div><div class="im">
This is a lib that spawns a process, I can't imagine why this library<br></div><div class="im">
should need to allocate a single byte, but it allocates wildly just to<br>
perform a trivial pass-through to the OS.<br>
</div></blockquote>
<br>
It is not a trivial pass-through.  Different OSes require different parameter types.  Look at the difference between the windows and posix implementations.  We are writing a cross-platform library, so whatever we pick will have to be converted on at least one OS.</blockquote>
<div><br></div><div style>Writing cross-platform code is my life.<br></div><div style>They are trivial conversions. It could be done on the stack easily.</div><div style>Granted, ideally the compiler could theoretically perform some of those improvements, but it doesn't, and probably depends on other changes to be able to do so anyway.</div>
<div style>For instance, the compiler couldn't confidently lower the allocations to the stack unless 'scope' arguments worked, so it knew it wouldn't escape the OS call it was being handed to.</div><div style>
<br></div><div style><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div class="im">
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
This module is no exception either, basically all of phobos is like this,<br>
and I'd like to see careful consideration made to these details in the<br>
future.<br>
</blockquote>
<br></div>
I too like to avoid memory allocations.  But the level to which you require is too stringent.  Not even Tango, which made low heap-allocations a priority, avoided allocations in it's process library.</blockquote><div>
<br></div><div style>But it would be trivial to use the stack in these cases. It doesn't matter if it adds a few lines under the hood.</div><div style><br></div><div style>I'm really just trying to make the point that it should ALWAYS be a key consideration, and people should make it habit to think about/criticise these things when accepting code into phobos.</div>
<div style>This is the standard library, it will be used in more D code than any other library ever. Why skimp here?</div><div><br></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div class="im">
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
I've said before, I sadly have to avoid phobos like the plague. Some<br>
modules (like this one) that provide fundamental functionality - not just<br>
helper functions - can't be avoided. Requirements for those should be extra<br>
strict in my opinion.<br>
</blockquote>
<br></div>
We cannot cater to all developers.</blockquote><div><br></div><div style>In this case you certainly can, it would be fairly trivial to do.</div><div><br></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
  To put all developers through a lot of pain in order to attract the fringe ones is not a practical goal.<br></blockquote><div><br></div><div style>What pain? Are you saying a stack variable is somehow hard?</div><div style>
If that's the case, then there's clearly some other fundamental tools missing from phobos.</div><div><br></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">

I think the convenience of std.process is what it is there for.  For the highest performance, you are able to call the OS functions directly.<br></blockquote><div><br></div><div style>No, it's to save (ideally) _all_ programmers the effort of rewriting this module themselves.</div>
<div style>This is exactly the sort of thing I waste loads of my life doing, rewriting wheels because the author was a PC programmer, and simply didn't give a shit.</div><div style>What a waste of life >_<</div>
<div style><br></div><div style>I re-iterate, maybe my points aren't of critical importance in relation to std.process specifically, I'm trying to raise some general issues with phobos submissions (that shouldn't exclude std.process either).</div>
</div></div></div>