Was: Re: Vote for std.process

Steven Schveighoffer schveiguy at yahoo.com
Fri Apr 12 09:01:15 PDT 2013


On Fri, 12 Apr 2013 09:42:43 -0400, Manu <turkeyman at gmail.com> wrote:

> On 12 April 2013 23:21, Lars T. Kyllingstad <public at kyllingen.net> wrote:
>
>> 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.
>>
>
> 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.

No, because it would have to be COW.

However, a string[string] literal that uses strings only must allocate the  
structure of the AA, not the strings themselves.

The compiler might be able to optimize this by figuring out how much  
memory to allocate in order to contain the entire AA structure, then  
create one block that has all the data in it.  It still needs a new block  
though, otherwise, what happens when you change an AA that was once a  
literal?

I think the best path forward is to replace the functions with a templated  
one that takes a indexable type as the env pointer.  Then one can optimize  
as much as one desires.

-Steve


More information about the Digitalmars-d mailing list