I'll try to clarify my question :
I have a function called Draw (which someone (XNA) calls her 60 times per second), and i have many objects to draw, so i have the following code : void Draw() { obj1.draw(); obj2.draw(); obj3.draw(); .... }
Is there will be a performance impact if instead i will create an event, which will be raised by Draw(), and all the objects would sign up for the event ?
In case i wansn't clear what i'm asking is : Does a call to a function by signing up to an event is different from a regular call ?
Regarding performance, I think Jon Skeet's example is pretty conclusive that delegates don't add any significant overhead to performance, and may even improve it.
One factor you do need to consider with events/delegates is handling unhooking objects listening to an event or your reference counts will not reset properly and you would find yourself with memory leaks. Avoid anonymous methods unless you're prepared to store references to them so they can be unwired on Dispose etc.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With