Frage

Is it possible to write C++/CLI code with usage of garbage collection, which will compile to native machine code (ahead of time, not JIT)?

War es hilfreich?

Lösung

In short: No (but see below)

In long:

If you use C++/CLI you automatically use IL-Code, which can be very easily decompiled with dotPeek or other tools. But you have GC ;)

If you only want to have some parts of your C++/CLI project to be native, then you can disable the "/clr" option for this files (or better: only enable the /clr option for files which really needs .net support!). Nut in the native parts you do not have GC ;(

Alternatively you can also mark special parts of your code with pragma managed/unmanaged

#pragma managed
#pragma unmanaged

NGEN create a pre-compiled image of the assembly, but does not hide the .net code; so this is only usefull yif you have startup timing problems with your assembly. It normally makes only sence if you have UI applications. Also a side-effect is that ngened assenblies are sometimes slower than jitted assemblies. So I never use ngen...

BUT:

But MS now has seen that this has several problems. MS is doing some kind of improvements in this scenario. Currently only for Store-Apps but I think this will also improved to work for "normal" .NET applications. That means: You can write .NET application with full GC support AND these application will compiled into NATIVE code, without using the IL data. Only for special situations you need to IL data (like XmlSerializer).

For more infos see: Microsoft .NET Native

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top