Was: Re: Vote for std.process

Lars T. Kyllingstad public at kyllingen.net
Fri Apr 12 06:21:04 PDT 2013


On Friday, 12 April 2013 at 07:04:23 UTC, Manu wrote:
>
> 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.

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.


> 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.

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:

void doStuff()
{
     auto p = alloca(100);
}

void main()
{
     foreach (i; 0 .. 1_000_000) doStuff();
}

This is of course fixable, but until that happens, I would 
consider alloca() a no-go for Phobos.


More information about the Digitalmars-d mailing list