C
C#2y ago
Gladiator

❔ Consider struct or class types for small event args

Do you consider to define small event args (e.g. two floats or ints inside) as struct type to avoid GC especially for events which happen frequently?
6 Replies
WhiteBlackGoose
Why not just pass them as parameters?
Anton
Anton2y ago
yes it has some limitations though, but it's often better than just passing a bunch of parameters. You'd want it to be a class (or a struct copy, it depends) if the function is async, uses delegates internally, or uses yield return. Otherwise, pass the argument struct with in
Gladiator
GladiatorOP2y ago
Clean code nameless params Action<int,float,int> vs Action<CustomType>
Anton
Anton2y ago
yeah, also if you're going full generic you can define a delegate type with an in T parameter so that you can pass the struct by reference
Gladiator
GladiatorOP2y ago
Yes, my problem OnValueChanged<old,new> e.g.
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server