Performance of Multicast Delegates and their Ordering in Comparison to an Array of Delegates
Under the hood, are multicast delegates implemented using contiguous memory to store the delegates or are they implemented using Linked List like structure?
It does not specific in the Unreal Documentation, but is the order in which delegates are added to the multi-cast delegate always guaranteed? Or are they randomly fired off regardless of their original order in which they were added to the multicast delegate.
What would be the advantages of multicast delegates over just a TArray of delegates where order is assured as well as the fact that would be stored in contiguous memory?
asked Dec 14 '15 at 01:55 AM in C++ Programming
The invocation list is an array of delegate instances.
The order of invocation is not guaranteed by the contract. Technically, the order depends on when delegates are inserted or removed. However, you should not rely on that, because we may change the internal implementation details in the future.
If you maintain your own array of delegates, then you would be in full control of the order of execution. That being said, such a design would also not be advisable, because it will temporarily couple the delegate handlers to each other. You should design your code in such a way that each handler can successfully execute regardless of whether and when any other handlers execute. The handlers should not have to know about each other's existence. Otherwise you're asking for subtle and very difficult to find bugs down the road.
answered Dec 14 '15 at 07:05 AM
Follow this question
Once you sign in you will be able to subscribe for any updates here