While we're on the subject of escape analysis...

Hxal hxal at freenode.irc
Thu Oct 30 20:37:42 PDT 2008


Hxal Wrote:
> A function whose return type is a scope reference type could take a hidden
> argument that implements an allocator interface. If the call site
> determines that the result never leaves its scope, it can pass the
> secondary stack allocator, otherwise the regular GC allocator.
> The new call which produces the returned object would then call the
> hidden argument to allocate memory.

I should have also noted that the secondary stack works better than
the regular stack, because it can accomodate dynamic type sizes.

Example:

scope Foo bar ()
{
    return new FooSubclass;
}

>     this (Foo n)
>     {
>         next = n;
>     }

The constructor should have been:

this (scope Foo n = null)
{
    next = n;
}

On a side note though, the scope notation is not perfect,
because it cannot accomodate nested references.
Eg. int** or int*[]
I'd use a postfix type modifier, eg. int*@*, int*@*@, int[]@,
but it's not very pleasing to the eye.




More information about the Digitalmars-d mailing list