Enforcing static closure

Piotr Szturmaj bncrbme at jadamspam.pl
Thu May 19 12:39:12 PDT 2011


I want to make a delegate of blocking I/O statement and pass it to a 
function. Then it will be called immediately. This delegate never 
escapes its creation scope, so I don't want heap closure allocation.

Will compiler create dynamic closure (e.g. with allocation) or static 
closure (with pointer to the stack)?

void recv(ubyte[] buf, out size_t len)
{
     // block until data is received
}

int numWaiters;

// will that "scope" enforce static closure?
void wait(scope void delegate() dg)
{
     numWaiters++;
     dg();
     numWaiters--;
}

void test()
{
     ubyte[] buf = new ubyte[1500];
     size_t len;

     wait( { recv(buf, len); } );
}


More information about the Digitalmars-d-learn mailing list