A little thought about .NET Framework, CTS, CLI, CLS, CLI and C#
/*
Author: Jiangong SUN
*/
Terms:
CTS: Common Type Specification
CLI: Common Language Infrastructure
CLS: Common Language Specification
CLR: Common Language Runtime
JIT: Just In Time
CIL: Common Intermediate Language
MSIL: MicroSoft Intermediate Language
VES: Virtual Execution System
NGEN: Native image GENerator
FCL: Framework Class Library
Relationships:
CLR <==> VES
Managed code <==> MSIL <==> CIL
Unmanaged code <==> native code <==> machine code
CLR, CTS, CLS and metadata specification are all parts of CLI.
CTS: Microsoft introduces CTS to intercommunicate among data types in different programming languages.
CLS: It defines rules that all .NET languages should respect, and it's part of CTS.
CLR is the Microsoft implementation of VES.
CLR contains: Garbage collector for automatic memory management, JIT for compilation from CIL to native code, Type checker, Debug engine, Security engine, Class loader, Thread support, Exception manager, Com marshaler.
Computers can only understand machine code.
Machine code is a sequence of binary (1 and 0).
C# is a compiled language, because it's compiled to CIL, and then it's interpreted by JIT to machine code.
The difference between compiled language and interpreted language is: Interpreted language will be executed by interpretor, line by line on local machine.
Compiled language:
More rapid execution speed, because it’s already compiledand targeted to local machine
Less memory usage, because it’s compiled
Interpreted language:
Independent platform, because it doesn’t need to be compiled
Code size is smaller than compiled code
.NET Framework: consists of Common Language Runtime and Class Library.
C# source code execution steps:
C# source code --C# Compiler(csc.exe) --> CIL/MSIL (managed code/ byte code) stores in assemblies like DLL or EXE --JIT in CLR or NGEN--> native code (unmanaged/machine code) --> Execution
Difference between managed code and native code/machine code/unmanaged code:
Code compiled by C# sharp compiler is called managed code, it's stored in assemblies like DLL or EXE files.
Managed code is the intermediate code between source code and native code.
Managed code is CPU independent code.
MSIL must be converted to CPU-specific code which is machine code to be run, it will be compiled by JIT compiler in CLR at runtime.
CLR supplies one or more JIT compilers for each computer architecture it supports, the same set of MSIL can be JIT-compiled and run on any supported architecture.
Native code runs straight on the CPU. They are machine code targeted towards a specific architecture (for instance, Intel's x86). It'sCPU-Specific code.
Native code is the code whose memory is not "managed". There is no reference counting, no garbage collection.
Difference between JIT and NGEN:
The Native Image Generator (Ngen.exe) is a tool that improves the performance of managed applications.
Ngen.exe creates native images, which are files containing compiled processor-specific machine code, and installs them into the native image cache on the local computer. The runtime can use native images from the cache instead of using the just-in-time (JIT) compiler to compile the original assembly.
补充:软件开发 , C++ ,