reflection - C# Runtime DLL loading and ref parameters -


in short, wish load .dll file @ runtime, , ask modify ref value passed parameter. (the .dll written in c#) don't know suitable technique be.

i have class "alotofdata" contains ~1 gigabyte worth of variables in it.

i want dynamically load .dll file contains method

"dowork(ref alotofdata thedata){ thedata.value = ... }

then execute method, , unload dll, , same dll. (very important have ability load/unload dlls @ runtime)

obviously, solution pass copy of value itself, return modified copy, , put class.

however, not possible, if dll file have make decision. based on data, data modify (consider: potentially needs access data).

merely copying entire package of data is... absolutely horrible idea, whole entirety of data 1 gigabyte large.

how can go importing method .dll dynamically (at run time) , pass parameter it, ref, , mean, pass reference, not copy it? (very important pass ref class, without copying)

a psuedo-code might explain point:

class alotofdata{ ... } // ~ 1gb of initialized values inside  main(){ dll = loaddll("mydll.dll"); dll.invoke("dowork",ref alotofdata); // needs change class's contents dll.unload(); } 

inside dll:

dowork(ref alotofdata data){     if(data.value){         foreach( value in data.value ){ ... } // ~100 iterations     } } 

i add decision making in main program, defeat purpose of being able load/unload dll files.

loading assembly @ runtime pretty easy:

assembly.loadfrom("mydll.dll"); 

unfortunately, there no way unload assembly. instead have unload entire appdomain assembly loaded into. have single appdomain contains running code; unloads when application exits.

if want able unload assemblies whilst running, must create second appdomain , load assembly there:

// create new domain dynamic assembly. var domain = appdomain.create("dynamic assembly domain"); domain.load("mydll.dll");  // work dynamic domain...  // unload domain. appdomain.unload(domain); 

the trouble here there boundary between appdomains has crossed communicate objects in each domain.

the problem (as seem aware of) default mechanism communicating between domains create copy of object. complete clone made , passed other domain, not suitable when working large amounts of information.

the answer problem type marshalbyrefobject:

marshalbyrefobject base class objects communicate across application domain boundaries exchanging messages using proxy. objects not inherit marshalbyrefobject implicitly marshal value. when remote application references marshal value object, copy of object passed across application domain boundaries.

marshalbyrefobject objects accessed directly within boundaries of local application domain. first time application in remote application domain accesses marshalbyrefobject, proxy passed remote application. subsequent calls on proxy marshaled object residing in local application domain.

so, in order pass data between domains without creating bulk copy, class providing data needs inherit marshalbyrefobject. should create type can loaded in remote domain inherits marshalbyrefobject, local domain has proxy remote domain:

// load 1gb of data. var data = alotofdata.load();  // create new domain dynamic assembly. var domain = appdomain.create("dynamic assembly domain"); domain.load("primary.dll"); // assembly containing primary code. domain.load("mydll.dll");  // create remote proxy. var remote = domine.createinstanceandunwrap("primary", "primary.remotecontrol");  // invoke logic in loaded dll. remote.execute("mydll", "mydll.dll", data);  // unload domain. appdomain.unload(domain); 

Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -