The new std.process is ready for review

Jonathan M Davis jmdavisProg at gmx.com
Tue Feb 26 11:52:47 PST 2013


On Tuesday, February 26, 2013 20:33:14 Lars T. Kyllingstad wrote:
> On Tuesday, 26 February 2013 at 18:24:08 UTC, Steven
> 
> Schveighoffer wrote:
> > On Tue, 26 Feb 2013 12:03:51 -0500, Lars T. Kyllingstad
> > 
> > <public at kyllingen.net> wrote:
> >> On Tuesday, 26 February 2013 at 16:45:08 UTC, Steven
> >> 
> >> Schveighoffer wrote:
> >>> On Tue, 26 Feb 2013 11:09:48 -0500, Lars T. Kyllingstad
> >>> 
> >>> <public at kyllingen.net> wrote:
> >>>> spawnProcess(["prog"]);
> >>> 
> >>> That allocates. I don't like that requirement.
> >> 
> >> 'scope string[] args' should tell the compiler not to allocate.
> > 
> > That's not how it works. The expression [<anything>] allocates.
> 
> Isn't that just a shortcoming of DMD? I thought 'scope' was all
> about avoiding such allocations.

scope is all about enforcing that what's being passed to a function does not 
escape it. To quote the docs ( http://dlang.org/function.html ).

---------
ref­er­ences in the pa­ra­me­ter can­not be es­caped (e.g. as­signed to a 
global vari­able)
---------

That has the added benefit of allowing the compiler to make optimizations (like 
not allocating a closure), but scope in and of itself doesn't necessarily mean 
that no allocation will occur. The spec says _nothing_ on that count. It 
doesn't even discuss scope in relation to delegates. All that's guaranteed is 
that no references to parameters marked with scope will escape.

However, regardless of all that, scope is currently only implemented for 
delegates (and even there, it's fairly buggy IIRC), so it will have zero effect 
on an array.

- Jonathan M Davis


More information about the Digitalmars-d mailing list