Tuesday, 30 December 2014

.Net Framework: All about CLR- Part I, Chapter 1, Section 1 - Post #2

Please see Post 1 before proceeding further.

Me: No Time, Lets go through heading One by One, a) What is PE32(+) Header?
Yendhr9014: PE32(+) header in a managed module, helps to identify bit version of windows, 32 or 64 bit. It also indicates the type of file, GUI, CUI or DLL and also contains the timestamp. For modules that contains IL code, this bulk of information in this header file will be ignored. If the module contains native CPU code, this header file will have native CPU code.

Me: Enough said about PE(+)header, b) what is meant by CLR header?
Yendhr9014: CLR header posses information about the version of CLR, metadata token of the managed module's entry point, that is static Main() method and location and size of metadata of managed module.

Me: Good, c) what is meant by Intermediate Language? IL?  is it a language which is in the mid of process between source code to object code?

Yendhr9014: Yes, you had it perfectly, IL code is the code generated by compiler from the source code, in our context its our Hello world program. This IL code will be taken by CLR and converted to native CPU code during the runtime. Sometimes IL codes referred as managed code because CLR manages its execution.

Me: What is managed code and unmanaged code?
Yendhr9014: The native codes which targets CPU architecture is called unmanaged code, the intermediate codes which needs CLR to run is called managed code.
Visual overview of the Common CLR Language Inf...
Visual overview of the Common CLR Language Infrastructure, and how the components relate to each other. Converted to SVG from PNG version, originally by Foofy from English Wikipedia. (Photo credit: Wikipedia)

Me: So all compilers will produce IL code from the source code?
Yendhr9014: No master, only CLR-compliant compilers produce IL code although native code compilers produce codes targeted to specific CPU architecture. Microsoft C++ compilers builds exe/dll modules which contains native code or unmanaged code. Dont worry if you use C++ compilers, because we can force compilers to generate IL codes using CLR command line switch. However you need CLR to be installed to run this managed codes. So C++ compilers are unique as it can generate both managed and unmanaged codes.

Me: Come some points about d) Metadata. Every book tells that it is a data about data. I need something more than that?
Yendhr9014: Every managed module contains metadata as tables, these are the information about types and members defined in the source code and the information about types and members referenced by our source code, here our hello world program. Metadata is the superset of older technologies such as COM's Type Libraries and Interface Definition Language files because the metadata is always associated to the file where IL code is present. There will not be any possibility to separate the metadata from IL code, they neither separable nor out of synchronisation.

Me: Cool, am now getting some picture about Metadata and IL code than earlier, It seems COM type libraries and Intermediate Definition Language concepts are simple but vast, you should explain them later for sure. Yendhr9014, can you say some more uses of having metadata?

Yendhr9014: Yes master, glad to serve you with more information, regarding uses of metadata,

  • Compilers can directly look into the metadata which implements type/members rather than looking for header files and library files of each source codes.
  • Intellisense fetches methods, properties, events, fields directly from metadata simpler and quicker. Thats why they immediately throw error if we have implementation errors.
  • CLR's code verification process uses metadata to ensure our hello world code performs type-safe operations.
  • Metadata allows an object's fields to be serialised to memory block and reversed in another machine.
  • Metadata allows garbage collector to track the lifetime of the objects and from the metadata know which fields within the object refers to the other objects.
Compiling  source code into managed modules - Ends

Questions for the next conversation
Me: What is meant by assemblies and its manifest?
Me: Are there any relationships between managed module and Assemblies? What are they?

30 Dec 2014

No comments:

Related Posts