Thursday, August 15, 2013

c++ managed and unmanaged new

 

Hashtable^ tempHash = gcnew Hashtable(iterators_);

IDictionaryEnumerator^ enumerator = tempHash->GetEnumerator();

 


http://stackoverflow.com/a/202464/2041023


gcnew is for .NET reference objects; objects created with gcnew are automatically garbage-collected; it is important to use gcnew with CLR types


 


http://stackoverflow.com/a/202473/2041023


This is C++/CLI and the caret is the managed equivalent of a * (pointer) which in C++/CLI terminology is called a 'handle' to a 'reference type' (since you can still have unmanaged pointers).

(Thanks to Aardvark for pointing out the better terminology.)

http://stackoverflow.com/a/14378351/2041023

// here normal pointer
P* ptr = new P; // usual pointer allocated on heap
P& nat = *ptr; // object on heap bind to native object
//.. here CLI managed
MO^ mngd = gcnew MO; // allocate on CLI heap
MO% rr = *mngd; // object on CLI heap reference to gc-lvalue

//In general, the punctuator % is to ^ as the punctuator & is to *. In C++ the unary & operator is in C++/CLI the unary % operator. While &ptr yields a P*, %mngd yields at MO^.

c++ cli v.s. clr

 

http://stackoverflow.com/a/480755/2041023

 

The CLR is Microsoft's implementation of the CLI standard.