Previous month:
January 2005
Next month:
March 2005

February 2005

C++/CLI Value Types and Memory Location

With C++/CLI value types can be put on the stack, or on the native or managed heaps.

value class MyData
  property int Simple;

Declaring the variable locally, the object is put on the stack.

MyData d1;
d1.Simple = 11;

Using the pointer syntax, the object can be put on the native heap:

MyData* pd2 = new MyData();
pd2->Simple = 22;
delete pd2;

With the gcnew operator boxing and unboxing is done behind the scenes:

MyData^ d3 = gcnew MyData();
d3->Simple = 33;
delete d3;   // invokes Dispose