Answers to Lao Zhao's interview questions (1)

Source: Internet
Author: User
Tags dot net dot net framework

I recently saw a blog post posted by Lao Zhao, "questions I asked during the interview with. Net/C # programmers". I tried to answer this question and I forgot to add it:

What is. Net? What is CLI? What is CLR? What is Il? What is JIT and how does it work? What is GC? How does GC work?

What is. net

Dot Net is a complete set of platforms proposed by Microsoft in 2000, including the underlying operating system: Windows; auxiliary products: dot NET Enterprise servers; mcirosoft XML Web Services :. net my services; Development Platform: dot NET Framework, integrated development environment: Visual Studio. The preceding components.

Underlying operating system: Of course, Windows provides XML Web Service Support for all operating systems. The personal operating system starts to integrate. NET Framework from Vista. In addition, the original API of the operating system began to be isolated by the dot net API. Its original conception was very large and radical, which was particularly evident in the Development of Vista, later, Microsoft cut off some features that were originally intended to be released on Vista. However, Vista has already been quite different from its predecessor. Of course, it is another topic that is not tortuous. In short, for the effort invested by Microsoft in the dot net program, we can clearly see that Microsoft attaches great importance to the dot net program.

Auxiliary products: you are familiar with SQL Server, and there have also been a rare change. The first is the integrated management tool that integrates the original enterprise manager, query analyzer, and tracker.

Microsoft XML Web Services: these are XML Web Services provided by Microsoft, and some of them are free of charge. (XML Web Services were "Explicit" in the past, but later development was not as successful as Microsoft expected)

Development Platform (Dot NET Framework): contains two parts: Common Language Runtime (CLR) and Dot NET framework class library (FCL. They provide consistent programming models, simplified programming methods, and reliable version mechanisms (using globalProgramSet cache GAC to avoid DLL hell), lightweight deployment management (the metadata provided by the Assembly can avoid INI files and registries ), extensive platform support (as long as this machine is compatible with the CLR and FCL standards, it can be deployed. Of course, il will become a local machine during running.Code), Seamless language integration (Java cross-platform, dot net cross-language, which is often seen in the debate at that time), Automated memory management (garbage collection ), type Security (CLR will prevent attacks using buffer overflow errors). CLR supports cross-language debugging and unified Error Reporting (say goodbye to the original error code ), the new security policy (CAS) is compatible with previous COM components.

Integrated Development Environment: Visual Studio can be used to create Windows applications and network applications on the Windows platform, or to create network services, smart device applications, and office plug-ins.

What is CLI?

The basic language infrastructure (CLI) is a subset of CLR, that is, the part of. Net that manages the runtime environment of applications compiled into msil code. In the CLR structure, the CLI is located in the lower half, mainly including class loader, real-time Compiler (IL to native compilers), and garbage collector in a runtime environment ). CLI is. net and CLR. cli provides the runtime environment for IL code. You can convert the code written in any language into msil code through its specific compiler and then run it, you can even write msil code and run it on CLI. As a core part of. NET and CLR, CLI and C # are also approved by ECMA (ECMA-335 ). With the C # And CLI standards, you can write your own. NET platform that can run on any operating system (as long as you want ). As mentioned above, the famous Mono Project does this. The Mono Project includes three core components: a c # Language compiler, a CLI, and a class library.

What is CLR?

CLR (Common Language Runtime) isProgramming Language"RunTime ". Core CLR functions (such as memory management, assembly loading, security, small exception handling, and thread synchronization) can be shared by all CLR languages.

What is Il?

In the Il intermediate language, after the dot net program is compiled, the Il code is formed. During running, the CLR compiles the Il CPU commands at a cost. Il code is also known as managed code. Il can access all CLR functions. Il can also be viewed as an object-oriented machine language, which can be compiled using an assembly language. The advantage of Il is that it verifies the code correctness (number of parameters and parameter type verification)

What is JIT and how does it work?

JIT (Just In Time) instant compiler, called by CLR, compiles the Il CPU commands at a cost.

When a piece of code is called for the first time, the CLR points to a special function contained in the CLR. This special function is jitcompiler, which is responsible for the instruction of IL compilation cost. Jitcompiler knows which method is actually called and which type of method is defined. jitcompiler searches for the Il of the called method in the metadata of the Assembly that defines this type, and compile the CPU commands at the local cost. The compiled result is placed in a memory block. Then, jitcompiler returns the internal data structure created by CLR for the type, finds the record corresponding to the actual call method, and modifies the original reference to jitcompiler, point it to the address of the CPU instruction that has just been compiled for the called method in the memory block. Finally, execute the CPU command of the called method.

What is GC? How does GC work?

Garbage Collection)

The garbage collection of dot net can be divided into two steps. The first step is to "mark". The Garbage Collector assumes that all objects are garbage, then start to traverse each "root" (the root contains a pointer to the referenced type object, and the value type object will never be considered as a root ), if a root references an object (not null), the object is marked. Unlabeled objects are considered as spams. The second stage is "compression". In fact, it is to move the following objects to the location where they have become garbage objects, making the original managed heap more compact. The managed heap is released.

Methods In the GC class affect when to recycle objects and when to release resources allocated to objects. The attributes in this class provide the following information: total available memory of the system, and the cycle type (generation) of the memory allocated to the object ).

GC tracks and recycles the objects allocated in the managed memory. The garbage collector periodically recycles the memory allocated to objects that are not effectively referenced. When the available memory cannot meet the memory request, garbage collection is automatically performed. Alternatively, applications can use the collect method to force garbage collection.

Garbage collection consists of the following steps:

GC searches for Managed Objects referenced in managed code.

GC attempts to complete objects that are not referenced.

GC releases objects that are not referenced and recycles their memory.

During the collection, If GC finds one or more references to an object in the managed code, the object will not be released. However, GC does not recognize references to objects in unmanaged code. Therefore, unless explicitly prohibited, GC may release objects that are exclusively used in unmanaged code. The keepalive method provides a mechanism to prevent the garbage collector from recycling objects that are still used in unmanaged code.

I have answered only one question. You are welcome to discuss it.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.