Datasheet
divided into a number of application domains. Each application domain roughly corresponds to a single
application, and each thread of execution will be running in a particular application domain (see
Figure 1-3).
Figure 1-3
If different executables are running in the same process space, they are clearly able to easily share data,
because theoretically they can directly see each other’s data. However, although this is possible in principle,
the CLR makes sure that this does not happen in practice by inspecting the code for each running appli-
cation, to ensure that the code cannot stray outside its own data areas. This looks at first sight like an
almost impossible trick to pull off — after all, how can you tell what the program is going to do without
actually running it?
In fact, it is usually possible to do this because of the strong type safety of the IL. In most cases, unless
code is using unsafe features such as pointers, the data types it is using will ensure that memory is not
accessed inappropriately. For example, .NET array types perform bounds checking to ensure that no out-
of-bounds array operations are permitted. If a running application does need to communicate or share
data with other applications running in different application domains, it must do so by calling on .NET’s
remoting services.
Code that has been verified to check that it cannot access data outside its application domain (other than
through the explicit remoting mechanism) is said to be memory type safe. Such code can safely be run along-
side other type-safe code in different application domains within the same process.
Error Handling with Exceptions
The .NET Framework is designed to facilitate handling of error conditions using the same mechanism,
based on exceptions, that is employed by Java and C++. C++ developers should note that because of IL’s
stronger typing system, there is no performance penalty associated with the use of exceptions with IL in
the way that there is in C++. Also, the
finally block, which has long been on many C++ developers’
wish list, is supported by .NET and by C#.
Exceptions are covered in detail in Chapter 13, “Errors and Exceptions.” Briefly, the idea is that certain
areas of code are designated as exception handler routines, with each one able to deal with a particular
PROCESS - 4GB virtual memory
APPLICATION DOMAIN:
an application uses some
of this virtual memor y
APPLICATION DOMAIN:
another application uses
some of this virtual memor y
16
Part I: The C# Language
24727c01.qxd:WroxPro 5/7/07 12:12 PM Page 16