Timeline for Is it worthwhile to use events when there’s only one subscriber?
Current License: CC BY-SA 4.0
7 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| 2 days ago | comment | added | Pikalek | I agree with the broad strokes, but"...the professor will probably expect you to use the event system regardless of if it's a good idea or not" is conjecture. Having been that professor, I'd recommend asking rather than guessing. Sometimes mandatory use of X is the point; sometimes it's up to the student(s) to make the call about how to get something done. | |
| 2 days ago | history | edited | Pikalek | CC BY-SA 4.0 |
fixed typos
|
| Nov 27 at 13:38 | comment | added | Themoonisacheese | @DMGregory effectively, since listeners are systematically unconditional branches, the low level .NET asm of firing the event looks like list of calls to each callback, which may be in a special memory region or may even be inlined if the number of callbacks is small enough. | |
| Nov 27 at 13:35 | comment | added | Themoonisacheese | @DMGregory The c# compiler (and by extension the whole .NET virtual machine stack, what exact part performs this type of optimization is unclear) should (in most cases at least) be able to reduce lists of callbacks to tail calls that are permitted to clobber the stack and have no return value, including in cases where there is only one such callback, but even moreso when there are multiple. this is a standard optimization in all .NET languages so i'd wager this is performed by the VM. | |
| Nov 27 at 12:19 | comment | added | DMGregory♦ | The point about compiler optimization is interesting, but I'm curious whether it applies in the case of the C# scripts we write in Unity (since that's the context for this question). I haven't seen anything about the C# compiler being able to optimize-away listener list traversal in cases where it detects there will be only one listener, but I'd love to be enlightened if that's the case! Do you (or does anyone) have a link where I could read more about that? | |
| S Nov 27 at 9:45 | review | First answers | |||
| 2 days ago | |||||
| S Nov 27 at 9:45 | history | answered | Themoonisacheese | CC BY-SA 4.0 |