On Fri, 12 Apr 2013 03:04:08 -0400, Manu <turkeyman@gmail.com> wrote:
I think you meant "without"?string[string] is used in the main API to receive environment variables;
perhaps kinda convenient, but it's impossible to supply environment
variables with loads of allocations.
What would be your suggestion? string[string] is the built-in map type. How do you pass an environment map without having some allocations?
This would be a lot of effort for pretty much zero gain for the majority of cases.toStringz is used liberally; alternatively, alloca() could allocate the
c-string's on the stack and zero terminate them there, passing a pointer to
the stack string to the OS functions.
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.String concatenation is rampant! Look at this code to parse the env
variables (which are already an AA):
foreach (var, val; childEnv)
envz[pos++] = (var~'='~val~'\0').ptr;
And many many more of the same...
This is a lib that spawns a process, I can't imagine why this libraryshould need to allocate a single byte, but it allocates wildly just to
perform a trivial pass-through to the OS.
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.
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.This module is no exception either, basically all of phobos is like this,
and I'd like to see careful consideration made to these details in the
future.
We cannot cater to all developers.I've said before, I sadly have to avoid phobos like the plague. Some
modules (like this one) that provide fundamental functionality - not just
helper functions - can't be avoided. Requirements for those should be extra
strict in my opinion.
To put all developers through a lot of pain in order to attract the fringe ones is not a practical goal.
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.