【正文】
另外, COM 組件仍 可以使用 —— .NET 組合了 COM 的互操作性,從而使托管代碼可以調(diào)用 COM 組件, COM 組件也可以調(diào)用托管代碼 (見第 29 章 )。 頁面可以用 編寫,現(xiàn)在可以把 當(dāng)作一種編譯語言來運(yùn)行,而不是解釋性的語 言,也可以編寫輸入量比較大的 代碼。 J不使用 Java 運(yùn)行庫,而是使用與其他 .NET 兼容語言一樣的基類庫。在 .NET Framework 版本推出之前,用戶必須下載相應(yīng)的軟件,才能使用 J。另外,在使用托管類時,還需要使用非標(biāo)準(zhǔn)的 C++特性 (例如上述代碼中的 __gc 關(guān)鍵字 )。 C++的一個有趣的問題是在編譯托管代碼時,編譯器可以生成包含內(nèi)嵌本機(jī)可執(zhí)行代碼的 IL。 (2) Visual C++ .NET Visual C++ 6 有許多 Microsoft 對 Windows 的特定擴(kuò)展。雖然這意味著其中的工作已大大減輕,但用戶仍需要檢查新的 代碼,以確保項目仍可正確工作,因為這種轉(zhuǎn)換并不十分完美。另外,它不支持繼承,Visual Basic 使用的標(biāo)準(zhǔn)數(shù)據(jù)類型也與 .NET 不兼容。 那么除了 C之外,還有什么語言可以通過 .NET 進(jìn)行交互操作呢?下面就簡要討論其他常見語言如何與 .NET 交互操作。例如 Visual Studio 6 優(yōu)化了一 臺一般的 Pentium 機(jī)器,所以它生成的代碼就不能利用 Pentium III 處理器的硬件特性。其原因是編譯過程的最后一部分是在運(yùn)行時進(jìn)行的, JIT 編譯器確切地知道程序運(yùn)行在什么類型的處理器上,利用該處理器提供的任何特性或特定的機(jī)器代碼指令來優(yōu)化最后的可執(zhí)行代碼。代碼編譯過一次后,得到的內(nèi)部可執(zhí)行代碼就存儲起來,直到退出該應(yīng)用程序為止,這樣在下次運(yùn)行這部分代碼時,就不需要重新編譯了。也就是說編譯為中間語言就可以獲得 .NET 平臺無關(guān)性,這與編譯為 Java 字節(jié)代碼就會得到 Java 平臺無關(guān)性是一樣的。 at runtime the final stage of pilation can then be easily acplished so that the code will run on that particular platform. In other words, by piling to IL we obtain platform independence for .NET, in much the same way as piling to Java byte code gives Java platform independence. You should note that the platform independence of .NET is only theoretical at present because, at the time of writing, a plete implementation of .NET is only available for Windows. However, there is a partial implementation available (see for example the Mono project, an effort to create an open source implementation of .NET, at ). Performance improvement Although we previously made parisons with Java, IL is actually a bit more ambitious than Java byte code. IL is always JustInTime piled (known as JIT pilation), whereas Java byte code was often interpreted. One of the disadvantages of Java was that, on execution, the process of translating from Java byte code to native executable resulted in a loss of performance (with the exception of more recent cases, where Java is JIT piled on certain platforms). Instead of piling the entire application in one go (which could lead to a slow startup time), the JIT piler simply piles each portion of code as it is called (justintime). When code has been piled once, the resultant native executable is stored until the application exits, so that it does not need to be repiled the next time that portion of code is run. Microsoft argues that this process is more efficient than piling the entire application code at the start, because of the likelihood that large portions of any application code will not actually be executed in any given run. Using the JIT piler, such code will never be piled. This explains why we can expect that execution of managed IL code will be almost as fast as executing native machi