Chapter 3: Inside the CLR


We think in generalities, but we live in details.
— Alfred North Whitehead

Overview

The Common Language Runtime (CLR) is the virtual execution system responsible for running all managed code. It's an implementation of the CLI — and therefore the CTS (see Chapter 2) — and offers a broad set of services, each of which takes a part in the execution of your code. These services include, but are not limited to, automatic memory management using an intelligent Garbage Collected (GC) memory heap, built on top of standard Windows memory facilities; metadata and module conventions to control the discovery, loading, layout, and analysis of managed libraries and programs; a rich exceptions subsystem to enable programs to communicate and respond to failures in structured ways; native and legacy code interoperability, supporting integration with, for example, Win32 and COM code; just-in-time(JIT) compilation of managed code to native, including support for both 32- and 64-bit (x64/AMD64, IA64) architectures; and a sophisticated code identity-based security infrastructure, among other things. Running managed code necessarily involves many moving parts.

Physically, the CLR is little more than a collection of DLLs containing sophisticated algorithms that interact with Windows via calls to various Win32 and COM APIs. Managed programs are just Windows DLLs whose code bootstraps the CLR as part of the Windows executable load sequence. If you examine the native code generated by the JIT, you'll notice calls into CLR DLLs scattered throughout your code. This, like many things on the CLR, is entirely transparent to your programs, and is easy to take for granted. It sounds pretty simple, doesn't it? But remember, this is the foundation on top of which all of your code runs. There is a lot of depth here. Having a solid understanding will enable you to become an expert in this technology, write better managed code, and give you an edge up on the next difficult bug you're trying to troubleshoot.

This chapter of course oversimplifies the runtime system by necessity for explanatory purposes. The CLR is a very complex machine that does some amazing things for your code. We'll drill into some facets of this machine in this chapter, detailing how the CLR accomplishes many of its tasks and what it means for your code. Many topics, however, such as assemblies and metadata (see Chapter 4), security (see Chapter 9), and unmanaged interoperability (see Chapter 11), are deferred to later chapters. Larger amounts of text are dedicated to them because they are deep topics and because as a managed code developer you will end up working directly or on more frequent occasion with them than many topics. Other topics are left for your own research due to the specialized knowledge and/or incredible depth necessary to form a solid understanding.




Professional. NET Framework 2.0
Professional .NET Framework 2.0 (Programmer to Programmer)
ISBN: 0764571354
EAN: 2147483647
Year: N/A
Pages: 116
Authors: Joe Duffy

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net