当前位置:网站首页>. net cross platform principle (Part I)

. net cross platform principle (Part I)

2022-04-23 17:04:00 begeneral

1、.NET Framework hierarchy

FCL(Framework Class Library)
BCL(Basic Class Library)
CLR(Common Language Runtime)

FCL: This is a for developers API Class library , For example, the framework we often use :Windows Forms、ASP.NET、WPF、WCF etc. . This layer is directly oriented to developers .

BCL: This is the class library at the bottom , Provide code that interacts with the operating system level , Such as :IO、 Thread management

CLR: It provides a managed execution environment for programs , yes .NET Framework Execution engine for .CLR And .NET The relationship of is equal to JVM And Java The relationship between ,CLR It's essentially .NET Virtual machine .

2、CLI

To achieve cross platform , The two types of differences must be addressed : Differences in programming languages and runtime environments . Only programming languages can achieve mutual compatibility , The runtime environment can be unified , Cross platform can be realized .CLI To solve such a problem : Developed by different high-level programming languages .NET Applications can run in different system environments without any change .

CLI Full name :Common Language Infrastructure. among Common Language It refers to the common language , It aims to solve the compatibility problem of various high-level development languages .Infrastructure Refers to the runtime environment , It aims to make up for the differences in execution methods between different platforms .

Programming languages are divided into two types: compiled and interpreted . The former needs to be compiled by the compiler to generate executable code ,CLI It involves compiled languages . To achieve true cross platform , The final problem to be solved is the compatibility and portability of executable code between different platforms . If the executable code generated by different programming languages after compilation is the same , So the difference between programming languages is no longer a problem .

2.1、CIL

according to CLI The provisions of the , Used to describe executable code is a kind of code called CIL(Common Intermediate Language) Language , This is an intermediate language between high-level language and machine language . Although the program source files are written in different programming languages , But we can compile it into CIL Code . In principle , Design a new programming language and add it to .NET in , You only need to use the corresponding compiler to generate a unified CIL The code can be . We can also design a compiler , take java The code is compiled to CIL For the target language . If you say so , In fact, programming languages are just appearances , Object code ( Also known as executable code ) That's the essence. , Because the object code deals directly with the computer . Now draw a picture to illustrate the function of intermediate language .

The differences of programming languages are unified through the compiler , The difference of running environment can be realized through virtual machine (VM) Technology to solve . Virtual machine is CIL Execution container for , Be able to perform CIL The code is dynamically translated into machine instructions that match the current execution environment by means of real-time compilation . Virtual machines mask the differences between different operating systems , So that the target program can run in different underlying execution environments without any modification .

That's the logic ,.NET The application should be able to work in non windows The platform is running , Why in the non windows The platform still doesn't work ? My personal understanding is : Microsoft didn't realize non - windows Virtual machine of platform , That is to say CLR. In other words, Microsoft has only realized windows Platform CLR, therefore .NET Applications can only be windows Platform execution .

 

 

 

 

 

版权声明
本文为[begeneral]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230554082479.html