29.1 Definitions


With so many new terms flying about, it is appropriate to clear the air before moving on. Table 29.1 defines some terms which will be needed in the discussion that follows .

Table 29.1. Definitions of managed versus unmanaged, and safe versus unsafe codes

Term

Meaning

Managed codes

Codes which run within the confines of the .NET CLR. Managed codes are first compiled into IL codes, then executed on-the-fly by the CLR. All your C# codes are managed “ you cannot write unmanaged codes using C#.

Unmanaged codes

Codes which do not run in the CLR, and are totally independent of it. Unmanaged codes will be native codes written for a specific operating system. Examples include legacy DLL files which run on top of the Win32 API directly.

Safe codes

Managed codes which have type safety and security embedded within. All the C# codes you have seen up to now are considered safe codes.

Unsafe codes

Managed codes which involve 'unsafe' operations, such as pointer operations which access memory directly. Unsafe codes must be marked by the unsafe modifier. Unsafe codes are seldom written by most application developers, unless they need the power provided by pointer operations. It is not possible to write unsafe codes in most .NET languages. C# and C ++ allow you to write unsafe codes, while VB .NET and J# do not have such a feature.

One important thing to understand is that both safe and unsafe codes are considered to be managed codes. Despite the use of pointer variables and other 'unsafe' stuff, unsafe codes still run within the confines of the .NET CLR (see Figure 29.1).

Figure 29.1. Managed codes run within the confines of the CLR, while unmanaged codes do not.

graphics/29fig01.gif

C# has three special keywords for writing unsafe codes only: sizeof , stackalloc , and fixed . Both the fixed and sizeof keywords will be covered in this chapter, but stackalloc is outside the scope of this book.



From Java to C#. A Developers Guide
From Java to C#: A Developers Guide
ISBN: 0321136225
EAN: 2147483647
Year: 2003
Pages: 221
Authors: Heng Ngee Mok

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