Unity3d Cross-platform principle

Source: Internet
Author: User
Tags emit

A question: Unity3d cross-platform principle

Some information:

IL

IL is an abbreviation for the intermediate language (intermediate Language) in the. NET Framework. Use. NET Framework provides a compiler that can directly compile the source program into an. exe or. dll file, but the program code compiled at this time is not a machine code that the CPU can execute directly, but an intermediate language Il (intermediate Language)

Advantages:The advantage of using the intermediate language is two points, one is to achieve platform-independent, not related to the specific CPU; just put. NET Framework to be compiled into IL code, the implementation of a language. NET Framework for interaction between languages (which is why Unity3d can be mixed in C # and JS)。 ("C # Program design and Application Tutorial" (2nd edition), June MA) Related terms:Xamarin

Xamarin(now being acquired by Microsoft) is a branch of the mono project, but the biggest difference is that Xamarin is a commercial project. Mono as a cross-platform framework has been affirmed by a growing number of commercial projects, making the issue of copyright issues \ Reliability Stability is also proven, and the biggest benefit of using mono is that it can use many project solutions from other platforms without being constrained to a variety of poor and expensive solutions under the Windows platform.

On Mac OS, because of the existing limitations of iOS, C # code for iOS is compiled directly into arm assembler code through AOT compilation technology. On Android, the application is converted to IL and then JIT-compiled at startup.

The limitations of mono in full AOT mode

A mono runtime exception was encountered while debugging:

12 ExecutionEngineException: Attempting to JIT compile method ‘...‘whilerunning with --aot-only.

The final reason for this is that the generic interface is used, which causes mono to be JIT-compiled, but in the iOS platform, Mono is running in full AOT mode and cannot use the JIT engine, and this exception is thrown.

Mono's AOT, like the. NET NGen, reduces JIT work by compiling ahead of time, but by default the AOT does not compile all IL code, but rather a balance between optimization and JIT. Because the iOS platform disables JIT compilation, Mono requires full AOT compilation and operation on iOS. That is, all IL code in the assembly is pre-AOT-compiled to generate a local code image and then load the image directly at run time without using the JIT engine. There are limitations to using the full AOT for technical or implementation reasons, so refer to the Monotouch documentation for a few common examples:

    • Generic virtual methods are not supported because, for generic code, mono passes static parsing to determine the type to instantiate and generate code, but static parsing cannot determine which method the runtime actually calls (C + + therefore does not support virtual-template functions).

    • P/invoke for generic classes are not supported.

    • You cannot assign a value to a non-null type using Property.setinfo in reflection at this time.

    • There is a problem with the value type as dictionary key, which actually implements the iequatable<t> type, because dictionary's default constructor uses equalitycomparer<tkey> . The default is the comparator, and for the type that implements the Iequatable<t>, Equalitycomparer<tkey> The default is to instantiate a class that implements the Iequalitycomparer<tkey> by reflection (you can refer to the implementation of equalitycomparer<t>). The solution is to implement a iequalitycomparer<tkey> yourself, and then use Dictionary<tkey, tvalue> (iequalitycomparer<tkey>) The constructor creates an dictionary instance.

    • No dynamic generation of code is allowed, System.Reflection.Emit is not allowed, and dynamically created types are not allowed.

    • The DLR and any DLR-based languages cannot be used because System.Reflection.Emit is not allowed.

    • Do not confuse Reflection.Emit and reflection, all of the reflected APIs are available

JIT and AOT:

Jit:http://en.wikipedia.org/wiki/just-in-time_compilation

Aot:http://en.wikipedia.org/wiki/aot_compiler

Http://www.mono-project.com/AOT

Unity3d Cross-platform principle

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.