I've seen this a few times over the past few weeks and I just have to know what's the point of it. Is there an advantage of doing that at run time?
Yes. There is.
A farly good explination..
To my knowlege, there are no advantage of doing so at runtime.
From a design point of view, a class should only describe one entity and can be nested if you have a relationsip between them.
Classes themself are partitioned into the namespaces wich also can be nested.
Classes and namespaces are just a logical grouping of your code, The runtime itself works with pysical enteties, aka asseblies.(exe, dlls ..dynamic or static)
So, you could take some of the classes that are seldomly used, and put them in different modules(files), and link them togheter to an assebly with assebly linker.The dlls containing your classes will only be loaded in memory when necessary.
( you can also make your project imports namesapce as small as possible. in vs 2003, vb windows apps imports the system, system.collection, system.data, system.diagnostics, system.drawing, system.windows.forms and microsof.visualbasic )
Your program starts with the main method, but before main executes, clr detects the types referenced by main and makes an internal structure that contains an entry for each metod. Each entry is the memory location to where the metod can be found.
When this structure are initializing, clr sends the entries to the JIT Compiler (its just a function of the clr) So the jit knows what methods is called, and searces the metadata tables for the il. The jit compiles the il code to native code and saves it in memory ( this code are saved in memory during the application lifetime, and any other calls to the same code are not compiled but just taken from memory) The jit goes back to the internal data structure, and replace the adress of the called metod (il code), with the adress block of the native code,and then jump to that location. When the code(native) return, the jit returns to the code in Main.
- SMac wrote:A farly good explination..
That one helped a lot. It also cleared up a mental block I was having in how to do something in one of my programs.
Thanks for the info everyone
Thread Closed
This thread is kinda stale and has been closed but if you'd like to continue the conversation, please create a new thread in our Forums,
or Contact Us and let us know.