This project is read-only.

using calc with plinq trouble

Aug 6, 2010 at 11:54 AM

First of all, Thank you for this great library,
I've encountered some problems with ILCalc when using it with plinq,
for example this test method sometimes will give me sintax error "amigous between constants c2 and c3"

[Test] public void Calc2() { var calc = new CalcContext<decimal>(); calc.Constants.Add("c1", 3); calc.Constants.Add("c2", 3); calc.Constants.Add("c3", 3); var s = new List<int>(); for (int i = 0; i < 100; i++) { s.Add(i); } s.AsParallel().ForAll(o => calc.Evaluate("c2+c3")); }

Am I doing something wrong ?


Aug 9, 2010 at 9:23 PM
Hello, Omu! Yeah, you do something wrong: 1. ILCalc's CalcContext<T> class is not designed to work properly in multi-threaded environment. 2. Method context.Evaluate() is slow and should be used only if you need to evaluate something only at once. 3. You may use context.CreateEvaluator("c1+c2") to create Evaluator<T> object, witch is thread-safe and may be used inside PLINQ queries. 4. Evaluator<T> object contains expression in compiled form and evaluates expressions much-much faster with different arguments values.
Aug 10, 2010 at 7:17 AM
Thank you, about the thing with "expressions much-much faster with different argument values" I use constants instead of arguments because I need to add them by name (c1 c2 .. cn names are taken from the database), so I actually do a foreach with calc.Constans.Add("c"+o.Id, o.value) that's why I can't use arguments, because I can't add them by name&value Cheers, Omu