Chapter 3: Inside the CLR

Overview

In this chapter, we will investigate certain aspects of how the CLR works under the hood. We're not going to try to be in any way comprehensive - that's hardly possible for a piece of software as powerful as the CLR. But we are going to select a few key topics to explore in detail. And in choosing topics I've deliberately emphasized areas that are frequently glossed over by other books or by the documentation.

We will start off by identifying the various parts of the .NET architecture - which leads us to examine the relationship between the formal ECMA definition of a common language infrastructure, and Microsoft's implementation of that standard. Then we'll move on to examine:

  • The type system. We'll dig under the hood of the type system and examine how value and reference types are actually represented in memory, as well as discussing some subtleties about the use of value types and boxed types. We'll also present a C++ sample that shows how you can find addresses of objects and access their in-memory representations.

  • Code validation and verification. We'll look at exactly what the JIT compiler does when it validates and verifies your code. We'll also examine the question of what exactly constitutes type-safe code. You probably learnt at an early stage in your .NET programming that type safety is important for preventing nasty things like memory corruption. We'll learn in this section what kinds of conditions a program has to satisfy to count as type-safe.

  • Managed and unmanaged code. You'll be used to the idea that you can use DllImport or COM Interop to call up unmanaged code - and C++ developers will also know that they can use C++ to embed unmanaged code in an assembly. We'll examine how this is done, and how the various techniques used to call unmanaged code (internal call, IJW, P/Invoke, COM Interop) work behind the scenes.

But first, let's look at the overall architecture of the CLR and the ECMA CLI standard.



Advanced  .NET Programming
Advanced .NET Programming
ISBN: 1861006292
EAN: 2147483647
Year: 2002
Pages: 124

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