In last post "Get user input from Console, ReadLine()", the returned oject from Console::ReadLine() is in data type of String^. ^ indicate that it is a handle to an object.
A handle to an object on the managed heap points to the "whole" object, and not to a member of the object.
See gcnew for information on how to create an object on the managed heap.
In Visual C++ 2002 and Visual C++ 2003, __gc * was used to declare an object on the managed heap. The ^ replaces __gc * in the new syntax.
The common language runtime maintains a separate heap on which it implements a precise, asynchronous, compacting garbage collection scheme. To work correctly, it must track all storage locations that can point into this heap at runtime. ^ provides a handle through which the garbage collector can track a reference to an object on the managed heap, thereby being able to update it whenever that object is moved.
Because native C++ pointers (*) and references (&) cannot be tracked precisely, a handle-to object declarator is used.
Member selection through a handle (^) uses the pointer-to-member operator (->).
Read more: http://msdn.microsoft.com/en-us/library/yk97tc08.aspx
No comments:
Post a Comment