__gc and __nogc:
- when native C++ code is recompiled with
/clr
, the classes don't automatically become managed and are marked__nogc;
If your class does meet the requirements of the CLR, however, you can make your class managed by marking it with the__gc
modifier to indicate that it is a garbage-collected class, or the__value
modifier to indicate that it is a CTS value type. - For .net 3.5, __gc is old syntax. To use it, should use /clr:oldsyntax switch;
- '__gc' can only be applied to a class, struct, interface, array or pointer;
- __gc class is very similar with ref class; __value is similar with value class;
- It is neccesarry to choose /clr swithc in .net 3.5 that ref class and value class are compiled .
#paragma managed(unmanaged):
Enable function-level control for compiling functions as managed or unmanaged.
They tell compiler the following code is managed or unmanaged;
gcroot
- To use it, include "vcclr.h";
- gcroot《T ^〉
is used with ref class or value class; - gcroot《T *〉
is used with __gc or __nogc; - Create handler/pointer of a mananged class object in unmanaged class, can use them;