Quickly understand Unity's IL2CPP

overview

Literally means the conversion of intermediate language to c++

work process

1. The csharp code is compiled into a .net Dll, and then converted into an intermediate language after tailoring.
2. The intermediate language is converted into c++.
3. Use the compiler of the specified platform to compile the c++ code together with the runtime into a DLL or executable file.
The code of the IL2CPP VM belongs to the runtime time code

above picture

insert image description here

more instructions

IL2CPP debugging

To debug C# code using IL2CPP, enable Script Debugging in the Build Settings and enable the InternetClient, InternetClientServer, and PrivateNetworkClientServer features in the Player settings or manifest before building the project. When building on top of a previous build, the manifest is not overwritten, so if you want to change functionality, you need to do it from the Visual Studio manifest editor.
The debugging process is the same as any other Unity platform

IL2CPP memory management

Although the code becomes static C++ after IL2CPP, the memory management still follows the C# method, which is why there is an IL2CPP VM at the end: it is responsible for providing services such as GC management and thread creation. Work. However, due to the removal of the work of IL loading and dynamic parsing, the IL2CPP VM can be made very small, and the game loading time is shortened

Advantages of IL2CPP

Faster speed
can use c++ compiler optimization, can reduce the size of the program
can be compatible with more platforms

Disadvantages of IL2CPP

Because of the use of AOT, it takes more time to compile, and
reflection-based features cannot be used in the code

References

https://docs.unity3d.com/cn/current/Manual/IL2CPP.html
https://docs.unity3d.com/cn/2020.3/Manual/windowsstore-debugging-il2cpp.html

This article introduces IL2CPP in depth
https://zhuanlan.zhihu.com/p/19972689

Guess you like

Origin blog.csdn.net/ak47007tiger/article/details/125844856