There are a lot of thoughts in my project. So, I fixed the delegates in the dictionaries. The problem is that I decided to use MethodInfo as dict keys, I tried to use a search method that looks something like this:
Func<T,R> LookUp(Func<T,R> m) { return (Func<T,R>)dict[m.Method]; }
But after several tests, I found out that giving the LookUp method using the function address, i.e. creating transition delegates on the fly, pretty slow, really slow:
class MyCls { public static void Operate(int whatever){ } } class MainClass { delegate void Doer<T>(T arg); static Dictionary<MethodInfo,Delegate> _dict = new Dictionary<MethodInfo,Delegate>(); public static void Main (string[] args) { Action<int> dg = MyCls.Operate; _dict[dg.Method] = Delegate.CreateDelegate(typeof(Action<int>),dg.Method);
So the question is this: to improve performance, should I change my approach and write some unsafe code (Are pointers to objects even supported by C #?) Or are there alternative solutions for such C # situations?
Please help me out of there!
source share