畢業(yè)設計外文資料翻譯-托管代碼的優(yōu)點_第1頁
畢業(yè)設計外文資料翻譯-托管代碼的優(yōu)點_第2頁
畢業(yè)設計外文資料翻譯-托管代碼的優(yōu)點_第3頁
畢業(yè)設計外文資料翻譯-托管代碼的優(yōu)點_第4頁
畢業(yè)設計外文資料翻譯-托管代碼的優(yōu)點_第5頁
已閱讀5頁,還剩5頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

1、畢業(yè)設計外文資料翻譯學 院: 專業(yè)班級: 計算機科學與技術12(1) 學生姓名: 學 號: 指導教師: 外文出處:(外文) Advantages of Managed Code 附 件:1.外文資料翻譯譯文; 2.外文原文 指導教師評語:該英文資料選擇合理,與畢業(yè)設計論文相關度高。專業(yè)術語翻譯的較準確,體現(xiàn)了一定的專業(yè)英語應用水平。能嚴格按照規(guī)定,翻譯材料能與原文能保持一致,字、詞數(shù)基本滿足要求,翻譯材料語句通順。翻譯工作能夠嚴格按照規(guī)定,達到考核、提高學生英語應用水平的目的,較好完成要求。簽名: 2015年 10 月 14日1外文資料翻譯譯文托管代碼的優(yōu)點Microsoft中間語言與Java

2、字節(jié)代碼共享一種理念:它們都是一種低級語言,語法很簡單(使用數(shù)字代碼,而不是文本代碼),可以非??焖俚剞D換為內部機器碼。對于代碼來說,這種精心設計的通用語法,有很大的優(yōu)點。1. 平臺無關性首先,這意味著包含字節(jié)代碼指令的同一個文件可以放在任一個平臺中,運行時編譯過程的最后階段可以很容易完成,這樣代碼就可以運行在該特定的平臺上。也就是說編譯為中間語言就可以獲得.NET平臺無關性,這與編譯為Java字節(jié)代碼就會得到Java平臺無關性是一樣的。注意.NET的平臺無關性目前只是一種可能,因為在編寫本書時,.NET只能用于Windows平臺,但人們正在積極準備,使它可以用于其他平臺。2. 提高性能JIT

3、編譯器并不是把整個應用程序一次編譯完(這樣會有很長的啟動時間),而是只編譯它調用的那部分代碼(這是其名稱由來)。代碼編譯過一次后,得到的內部可執(zhí)行代碼就存儲起來,直到退出該應用程序為止,這樣在下次運行這部分代碼時,就不需要重新編譯了。Microsoft認為這個過程要比一開始就編譯整個應用程序代碼的效率高得多,因為任何應用程序的大部分代碼實際上并不是在每次運行過程中都執(zhí)行。使用JIT編譯器,從來都不會編譯這種代碼。這解釋了為什么托管IL代碼的執(zhí)行幾乎和內部機器代碼的執(zhí)行速度一樣快,但是并沒有說明為什么Microsoft認為這會提高性能。其原因是編譯過程的最后一部分是在運行時進行的,JIT編譯器確

4、切地知道程序運行在什么類型的處理器上,利用該處理器提供的任何特性或特定的機器代碼指令來優(yōu)化最后的可執(zhí)行代碼。傳統(tǒng)的編譯器會優(yōu)化代碼,但它們的優(yōu)化過程是獨立于代碼所運行的特定處理器的。這是因為傳統(tǒng)的編譯器是在發(fā)布軟件之前編譯為內部機器可執(zhí)行的代碼。即編譯器不知道代碼所運行的處理器類型,例如該處理器是x86兼容處理器或Alpha處理器,這超出了基本操作的范圍。例如Visual Studio 6優(yōu)化了一臺一般的Pentium機器,所以它生成的代碼就不能利用Pentium III處理器的硬件特性。相反,JIT編譯器不僅可以進行Visual Studio 6所能完成的優(yōu)化工作,還可以優(yōu)化代碼所運行的特定

5、處理器。3. 語言的互操作性使用IL不僅支持平臺無關性,還支持語言的互操作性。簡言之,就是能將任何一種語言編譯為中間代碼,編譯好的代碼可以與從其他語言編譯過來的代碼進行交互操作。那么除了C#之外,還有什么語言可以通過.NET進行交互操作呢?下面就簡要討論其他常見語言如何與.NET交互操作。(1) Visual Basic.NETVisual Basic 6在升級到Visual Basic .NET時,經歷了一番脫胎換骨的變化。Visual Basic是在最近的幾年中演化的,其早期版本Visual Basic 6并不適合運行.NET程序。例如,它與COM的高度集成,且只把事件處理程序作為源代碼顯

6、示給開發(fā)人員,大多數(shù)后臺代碼不能用作源代碼。另外,它不支持繼承,Visual Basic使用的標準數(shù)據類型也與.NET不兼容。Visual Basic 6已經升級為Visual Basic .NET,對VB進行的改變非常大,完全可以把Visual Basic .NET當作是一種新語言?,F(xiàn)有的VB6代碼不能編譯為VB.NET代碼,把VB6程序轉換為VB.NET時,需要對代碼進行大量的改動,但大多數(shù)修改工作都可以由Visual Basic .NET自動完成。如果要把一個VB6項目讀取到Visual Basic .NET中,Visual Basic .NET就會升級該項目,也就是說把VB6源代碼重寫

7、為VB.NET源代碼。雖然這意味著其中的工作已大大減輕,但用戶仍需要檢查新的VB.NET代碼,以確保項目仍可正確工作,因為這種轉換并不十分完美。這種語言升級的一個副作用是不能再把VB.NET編譯為內部可執(zhí)行代碼了。VB.NET只編譯為中間語言,就像C#一樣。如果需要繼續(xù)使用VB6編寫程序,就可以這么做,但生成的可執(zhí)行代碼會完全忽略.NET Framework,如果繼續(xù)把Visual Studio作為開發(fā)環(huán)境,就需要安裝Visual Studio 6。(2) Visual C+ .NETVisual C+ 6有許多Microsoft對Windows的特定擴展。通過Visual C+ .NET,又

8、加入了更多的擴展內容,來支持.NET Framework?,F(xiàn)有的C+源代碼會繼續(xù)編譯為內部可執(zhí)行代碼,不會有修改,但它會獨立于.NET運行庫運行。如果要讓C+代碼在.NET Framework中運行,就要在代碼的開頭添加下述命令:#using 還要把標記/clr傳遞給編譯器,編譯器假定要編譯托管代碼,因此會生成中間語言,而不是內部機器碼。C+的一個有趣的問題是在編譯托管代碼時,編譯器可以生成包含內嵌本機可執(zhí)行代碼的IL。這表示在C+代碼中可以把托管類型和非托管類型合并起來,因此托管C+ 代碼: class MyClass定義了一個普通的C+類,而代碼:_gc class MyClass生成了一

9、個托管類,就好像使用C#或VB.NET編寫類一樣。實際上,托管C+比C#更優(yōu)越的一點是可以在托管C+代碼中調用非托管C+類,而不必采用COM交互功能。如果在托管類型上試圖使用.NET不支持的特性(例如,模板或類的多繼承),編譯器就會出現(xiàn)一個錯誤。另外,在使用托管類時,還需要使用非標準的C+特性(例如上述代碼中的_gc關鍵字)。因為C+允許低級指針操作,C+編譯器不能生成可以通過CLR內存類型安全測試的代碼。如果CLR把代碼標識為內存類型安全是非常重要的,就需要用其他一些語言編寫源代碼,例如C# 或VB.NET。(3) Visual J# .NET最新添加的語言是J#。在.NET Framewo

10、rk 1.1版本推出之前,用戶必須下載相應的軟件,才能使用J#?,F(xiàn)在J#語言內置于.NET Framework中。因此,J#用戶可以利用Microsoft希望大多數(shù)J+用戶認為他們在使用.NET時,將很容易使用J#。J#不使用Java運行庫,而是使用與其他.NET兼容語言一樣的基類庫。這說明,與C#和VB.NET一樣,可以使用J#創(chuàng)建ASP.NET Web應用程序、Windows窗體、XML Web服務和其他應用程序。(4) 腳本語言腳本語言仍在使用之中,但由于.NET的推出,一般認為它們的重要性在降低。另一方面,JScript升級到JScript.NET。ASP.NET頁面可以用JScrip

11、t.NET編寫,現(xiàn)在可以把JScript.NET當作一種編譯語言來運行,而不是解釋性的語言,也可以編寫輸入量比較大的JScript.NET代碼。有了ASP.NET后,就沒有必要在服務器端的Web頁面上使用腳本語言了,但VBA仍用作Office文檔和Visual Studio宏語言。(5) COM和COM+從技術上講,COM 和COM+并不是面向.NET的技術,因為基于它們的組件不能編譯為IL(但如果原來的COM組件是用C+編寫的,使用托管C+,在某種程度上可以這么做)。但是,COM+仍然是一個重要的工具,因為其特性沒有在.NET中完全實現(xiàn)。另外,COM組件仍可以使用.NET組合了COM的互操作

12、性,從而使托管代碼可以調用COM組件,COM組件也可以調用托管代碼。在大多數(shù)情況中,把新組件編寫為.NET組件,其多數(shù)目的是為了更加方便,因為這樣可以利用.NET基類和托管代碼的其他優(yōu)點。2.外文原文Advantages of Managed CodeMicrosoft intermediate language shares with Java byte code the idea that it is a low-level language with a simple syntax , which can be very quickly translated into native ma

13、chine code. Having this well-defined universal syntax for code has significant advantages.Platform independenceFirst, it means that the same file containing byte code instructions can be placed on any platform; at runtime the final stage of compilation can then be easily accomplished so that the cod

14、e will run on that particular platform. In other words, by compiling to IL we obtain platform independence for .NET, in much the same way as compiling to Java byte code gives Java platform independence.Performance improvementIL is actually a bit more ambitious than Java byte code. IL is always Just-

15、In-Time compiled (known as JIT), 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.Instead of compiling the entire application in one go (which c

16、ould lead to a slow start-up time), the JIT compiler simply compiles each portion of code as it is called (just-in-time). When code has been compiled.once, the resultant native executable is stored until the application exits, so that it does not need to be recompiled the next time that portion of c

17、ode is run. Microsoft argues that this process is more efficient than compiling 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 compiler, such code will never be compiled.Thi

18、s explains why we can expect that execution of managed IL code will be almost as fast as executing native machine code. What it doesnt explain is why Microsoft expects that we will get a performance improvement. The reason given for this is that, since the final stage of compilation takes place at r

19、untime, the JIT compiler will know exactly what processor type the program will run on. This means that it can optimize the final executable code to take advantage of any features or particular machine code instructions offered by that particular processor.Traditional compilers will optimize the cod

20、e, but they can only perform optimizations that are independent of the particular processor that the code will run on. This is because traditional compilers compile to native executable before the software is shipped. This means that the compiler doesnt know what type of processor the code will run

21、on beyond basic generalities, such as that it will be an x86-compatible processor or an Alpha processor. Visual Studio 6, for example, optimizes for a generic Pentium machine,so the code that it generates cannot take advantage of hardware features of Pentium III processors. On the other hand, the JI

22、T compiler can do all the optimizations that Visual Studio 6 can, and in addition it will optimize for the particular processor the code is running on.Language interoperabilityThe use of IL not only enables platform independence; it also facilitates language interoperability. Simply put, you can com

23、pile to IL from one language, and this compiled code should then be interoperable with code that has been compiled to IL from another language.Youre probably now wondering which languages aside from C# are interoperable with .NET, so lets briefly discuss how some of the other common languages fit in

24、to .NET.Visual Basic .NETVisual Basic .NET has undergone a complete revamp from Visual Basic 6 to bring it up-to-date with .NET. The way that Visual Basic has evolved over the last few years means that in its previous version, Visual Basic 6, it was not a suitable language for running .NET programs.

25、 For example, it is heavily integrated into COM and works by exposing only event handlers as source code to the developermost of the background code is not available as source code. Not only that, it does notsupport implementation inheritance, and the standard data types Visual Basic 6 uses are inco

26、mpatible with .NET. Visual Basic 6 was upgraded to Visual Basic .NET, and the changes that were made to the language are so extensive you might as well regard Visual Basic .NET as a new language. Existing Visual Basic 6 code does not compile as Visual Basic .NET code. Converting a Visual Basic 6 pro

27、gram to Visual Basic .NET requires extensive changes to the code. However, Visual Studio .NET (the upgrade of VS for use with .NET) can do most of the changes for you. If you attempt to read a Visual Basic 6 project into Visual Studio .NET, it will upgrade the project for you, which means that it wi

28、ll rewrite the Visual Basic 6 source code into Visual Basic .NET source code. Although this means that the work involved for you is heavily cut down, you will need to check through the new Visual Basic .NET code to make sure that the project still works as intended because the conversion might not b

29、e perfect. One side effect of this language upgrade is that it is no longer possible to compile Visual Basic .NET to native executable code. Visual Basic .NET compiles only to IL, just as C# does. If you need to continue coding in Visual Basic 6, you may do so, but the executable code produced will

30、completely ignorethe .NET Framework, and youll need to keep Visual Studio 6 installed if you want to continue to work in this developer environment.Visual C+ .NETVisual C+ 6 already had a large number of Microsoft-specific extensions on Windows. With Visual C+ .NET, extensions have been added to sup

31、port the .NET Framework. This means that existing C+ source code will continue to compile to native executable code without modification. It also means, however, that it will run independently of the .NET runtime. If you want your C+ code to run within the .NET Framework, then you can simply add the

32、 following line to the beginning of your code: #using You can also pass the flag /clr to the compiler, which then assumes that you want to compile to managed code, and will hence emit IL instead of native machine code. The interesting thing about C+ isthat when you compile to managed code, the compi

33、ler can emit IL that contains an embedded native executable. This means that you can mix managed types and unmanaged types in your C+ code. Thus the managed C+ code:class MyClassdefines a plain C+ class, whereas the code: _gc class MyClasswill give you a managed class, just as if youd written the cl

34、ass in C# or Visual Basic .NET. The advantageof using managed C+ over C# code is that we can call unmanaged C+ classes from managed C+ code without having to resort to COM interop.The compiler raises an error if you attempt to use features that are not supported by .NET on managed types (for example

35、, templates or multiple inheritance of classes). You will also find that you will need to use nonstandard C+ features (such as the _gc keyword shown in the previous code) when using managed classes.Because of the freedom that C+ allows in terms of low-level pointer manipulation and so on, the C+ com

36、piler is not able to generate code that will pass the CLRs memory type safety tests. If its important that your code is recognized by the CLR as memory type safe, then youll need to write your source codein some other language (such as C# or Visual Basic .NET).Visual J# .NETThe latest language to be

37、 added to the mix is Visual J# .NET. Prior to .NET Framework 1.1, users were able to use J# only after making a separate download. Now the J# language is built into the .NET Framework. Because of this, J# users are able to take advantage of all the usual features of Visual Studio.NET. Microsoft expe

38、cts that most J+ users will find it easiest to use J# if they want to work with .NET.Instead of being targeted at the Java runtime libraries, J# uses the same base class libraries that the rest of the .NET compliant languages use. This means that you can use J# for building ASP.NET Web applications,Windows Forms, XMLWeb services, and everything else that is possiblejust as C# and Visual Basic .NET can.Scripting languagesScripting language

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
  • 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論