Saadli,
You can take my words with a grain of salt because I haven't been following the CLR section of the book, I've mostly been on the Native part.
However page 207, under the Tracking Handles topic, it says that:
- ...variables allocated on the CLR heap, which includes all CLR reference types, cannot be declared at global scope.
When I try to define a global like this:
I get this compiler error:
error C3145: 'value' : global or static variable may not have managed type 'System::Int32 ^' 1> may not declare a global or static variable, or a member of a native type that refers to objects in the gc heap
I can only imagine that the value variable is indeed a heap value, as a definition like this works fine at global scope:
Code:
int value = 99; // Definitely on the stack
That being the case, I cannot tell you what the real difference is between these definitions:
Code:
int^ value = 99;
int^ value = gcnew int(99);
The compiler gives the same error (C3145) for each of these global definition.
Here's a link about handles that you can paste into the URL field of the VS2008 help: ms-help://MS.VSCC.v90/MS.MSDNQTR.v90.en/dv_vclang/html/70c411e6-be57-4468-a944-6ea7be89f392.htm
Hope this helps...