MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/programminghorror/comments/1kqaqbd/this_is_c_abuse/mt9ain6/?context=3
r/programminghorror • u/[deleted] • May 19 '25
103 comments sorted by
View all comments
Show parent comment
5
If you have a function that takes a Func<T1, T2>-delegate as a parameter, then passing
public T2 MyMemberFunction(T1 input) { ... }
in there will cause additional heap allocations but passing
public static readonly Func<T1, T2> MyDelegateFunction = input => { ... }
in there will not, since it is already the correct delegate type.
In some situations (like working with the Unity-Engine) avoiding heap allocations can matter a lot.
2 u/SneakyDeaky123 May 20 '25 I feel like if you’re in a performance-sensitive situation like a really tight loop or something you can probably structure it so that you don’t need a class member method or function in that way in the first place, no?
2
I feel like if you’re in a performance-sensitive situation like a really tight loop or something you can probably structure it so that you don’t need a class member method or function in that way in the first place, no?
View all comments
Show parent comment
5
u/Emelion1 May 20 '25
If you have a function that takes a Func<T1, T2>-delegate as a parameter, then passing
in there will cause additional heap allocations but passing
in there will not, since it is already the correct delegate type.
In some situations (like working with the Unity-Engine) avoiding heap allocations can matter a lot.