jeudi 25 juin 2015

C# Runtime DLL loading and ref parameters

In short, I wish to load a .DLL file at runtime, and ask it to modify a ref value that I passed to it as a parameter. (the .DLL would be written in C#)

I have a class "ALotOfData" which contains ~1 Gigabyte worth of variables in it.

I want to dynamically load a .DLL file which contains a method

"DoWork(ref ALotOfData thedata){ thedata.value = ... }

then execute the method, and then unload the DLL, and do the same with another DLL. (VERY important to have the ability to load/unload DLLs at runtime)

Obviously, a solution would be to pass a copy of the value itself, return the modified copy, and put it back into my class.

However, this is not possible, if the DLL file will have to make a decision. based on the data, which data to modify (consider: it potentially needs access to all the data).

Merely copying the entire package of data is... an absolutely horrible idea, as the whole entirety of the data is about 1 gigabyte large.

How can I go about importing a method from a .DLL dynamically (at run time) and pass a parameter to it, by ref, and I mean, actually pass a reference, not just copy it? (very important to pass a ref to the class, without copying)

A psuedo-code might help explain my point:

class ALotOfData{ ... } // ~ about 1GB of initialized values inside

Main(){
DLL = loadDLL("mydll.dll");
DLL.Invoke("DoWork",ref AlotOfData); // This needs to actually change my class's contents
DLL.unload();
}





Aucun commentaire:

Enregistrer un commentaire