Christian Nagel's OneNotes

.NET Training, Consulting, Coaching - C#, Web Services, Enterprise Services, ASP.NET, Whidbey, Longhorn and More!

Affiliations

Books I've written

INETA UG Leaders

My Blogroll

February 2005 - Posts

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

Christian

Posted: Feb 28 2005, 02:05 PM by CNagel | with 3 comment(s)
Filed under: ,
More Posts