❔ 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
Why not just pass them as parameters?
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
Clean code
nameless params
Action<int,float,int> vs Action<CustomType>
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 referenceYes, my problem OnValueChanged<old,new> e.g.
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.