With async, the delegate *is* copied, you just don't see it in the Vala code. With an async method, when the thread of execution yields, the state of the function at that point is stored (copied or ref'd) in a context structure. When the thread of execution resumes later, the state is pulled back out and the function resumes.
To see this, try examining the C code valac generates (use the --save-temps argument). You'll see in the async version of the f2() function an F2Data struct being allocated and all the arguments being stuffed into it. That's where the delegate is being copied. -- Jim On Mon, Jun 20, 2011 at 5:26 PM, Nor Jaidi Tuah <[email protected]>wrote: > On Mon, 2011-06-20 at 13:06 -0700, Jim Nelson wrote: > > Regarding copying delegates, it is intentional. The Vala Journal has > > a nice write-up about ways to work around the problem: > > > > http://valajournal.blogspot.com/2011/06/vala-0130-released.html > > This is not about copying delegates. Consider the > example in the vala tutorial: > > delegate void DelegateType(int a); > > void f1(int a) { > stdout.printf("%d\n", a); > } > > void f2(DelegateType d, int a) { > d(a); // Calling a delegate > } > > void main() { > f2(f1, 5); > } > > This example compiles with no problem. But if we make > f2 async, i.e., > > async void f2(DelegateType d, int a) { > d(a); // Calling a delegate > } > > the warning appears. > > hand > Nor Jaidi Tuah > > > _______________________________________________ > vala-list mailing list > [email protected] > http://mail.gnome.org/mailman/listinfo/vala-list >
_______________________________________________ vala-list mailing list [email protected] http://mail.gnome.org/mailman/listinfo/vala-list
