Dynamic Closure + Lazy Arguments = Performance Killer?
Frits van Bommel
fvbommel at REMwOVExCAPSs.nl
Sat Oct 25 10:17:34 PDT 2008
> On Sat, Oct 25, 2008 at 10:44 AM, Denis Koroskin <2korden at gmail.com> wrote:
>> I also think that scope and heap-allocated delegates should have different
>> types so that no imlicit casting from scope delegate to heap one would be
>> possible. In this case callee function that recieves the delegate might
>> demand the delegate to be heap-allocated (because it stores it, for
>> example).
How would this work? For example:
-----
struct Struct {
// fields...
void foo() {
// body
}
}
void bar(Struct* p) {
auto dg = &p.foo; // stack-based or heap-based delegate?
// do stuff with dg
}
-----
?
(There's no way to know if *p is a heap-based or stack-based struct)
Jarrett Billingsley wrote:
> Fantastic. That also neatly solves the "returning a delegate"
> problem; it simply becomes illegal to return a scope delegate.
Even if "scope delegate" becomes a different type, sometimes such a
"scope delegate"s is perfectly safe to return:
-----
alias scope void delegate() dg;
Dg foo(Dg dg) {
return dg; // Why would this be illegal?
}
-----
More information about the Digitalmars-d
mailing list