Since the application is being written in .Net my initial thought was
to use VSA. Using this technique I was running into serious memory
leaks (on the order of 1M for each batch of scripts) on each test run.
Next I switched to manually using CodeDom and creating a new AppDomain
for each batch of scripts using a class factory approach. This worked
much better, but still results in leaking about 400 bytes for each
batch of scripts run. Plus I could only run about 6 batches of scripts
per second. Following are the compiler parameters being set which are
meant to be as efficient as possible:
CompilerParameters cParams = new CompilerParameters();
cParams.CompilerOptions = "/target:library /optimize";
cParams.GenerateExecutable = false;
cParams.GenerateInMemory = true;
cParams.IncludeDebugInformation = false;
After a lot of testing and debate I decided to test out using the
Microsoft Script Control. The results were over 300 times faster
(2,887 batches of scripts per second versus 6) with no memory leaks.
Following is a sample of what I put into a test loop:
MSScriptControl.ScriptControl sc = new
MSScriptControl.ScriptControlClass();
sc.Language = "VBScript";
sc.AddCode(TestCOMScript);
Object[] oParams = new Object[2] { new Random().Next(1000), new
Random().Next(1000) };
sc.Run("GetNumber", ref oParams).ToString();
System.Runtime.InteropServices.Marshal.ReleaseComObject(sc);
The decision seems to be a no-brainer, but I wanted to see if anyone
has an idea of how this can be accomplished using only managed code but
without such a large performance hit or the memory leaks. I really
hate to use an ActiveX object on an otherwise purely managed
application.
This is exactly why I've started to write a purely managed scripting engine
for .NET. Microsoft has, for some unknown reasons, forsaken the interpreting
script support and forces us to compile everything instead (which is
completely unnecessary when you want to execute dynamic code). Or at least
I'm not aware of any managed way to execute code dynamically without
compiling.
BTW., I've finally found some time to get back to my scripting library (I've
announced it some time ago), so some early bits should be available soon.
Stefan
<fred_...@yahoo.com> wrote in message
news:1104178244....@f14g2000cwb.googlegroups.com...