Saturday, 29 August 2009

Understanding Managed Modules

  • The common language runtime (CLR) is just what its name says it is; a runtime that is usable by different and varied programming languages. The features of the CLR are available to any and all programming languages that target it—period.
  • In fact, at runtime, the CLR has no idea which programming language the developer used for the source code. This means that you should choose whatever programming language allows you to express your intentions most easily.
  • When you compile the English like source code written in your preferred language, C# is most preferred I guess, the compiler does the syntax checking and source code analysis. It then produces a Managed Module .
  • A managed module is a standard 32-bit Microsoft Windows portable executable (PE32) file or a standard 64-bit Windows portable executable (PE32+) file that requires the CLR to execute.
  • Microsoft ships two command-line utilities, DumpBin.exe and CorFlags.exe, that you can use to examine the header information emitted in a managed module by the compiler.
  • The following are the parts of a managed module:
    • PE32 or PE32+ header
      • If the header uses the PE32 format, the file can run on a 32-bit or 64-bit version of Windows. If the header uses the PE32+ format, the file requires a 64-bit version of Windows to run.
      • For modules that contain only IL code, the bulk of the information in the PE32(+) header is ignored. For modules that contain native CPU code, this header contains information about the native CPU code.
    • CLR Header
      • Contains the information (interpreted by the CLR and utilities) that makes this a managed module.
      • The header includes the version of the CLR required, some flags, managed module's entry point method (Main method), and the location/size of the module's metadata, resources, strong name etc.
    • Metadata
      • Every managed module contains metadata tables.
      • There are two main types of tables:
        • tables that describe the types and members defined in your source code and
        • tables that describe the types and members referenced by your source code.
    • Intermediate Language (IL) code
      • It's the code the compiler produces as it compiled the source code. At run time, the CLR compiles the IL into native CPU instructions.

No comments: