Escape analysis

Denis Koroskin 2korden at gmail.com
Tue Oct 28 12:21:13 PDT 2008


On Tue, 28 Oct 2008 16:54:15 +0300, Steven Schveighoffer  
<schveiguy at yahoo.com> wrote:
[snip]
> What I'd prefer is allocate closure when you can prove it, allow
> specification when you can't.  That is, allocate a closure automatically  
> in simple cases like this:
>
> int *f() {int x = 5; return &x;}
>

Hmm.. This is nice! You can implement 'new' in pure D in just a few lines:

template new(T)
{
     T* new(Args...)(Args args)
     {
         T t = T(args);
         return &t;
     }
}

Example:

struct Foo
{
     public this(int value) {
         this.value = value;
     }

     private int value;
}

Foo* foo = new!(Foo)(42);



More information about the Digitalmars-d mailing list