Common Type System—Memory Layout


Jump to: navigation, search
CSharp-Online.NET:Articles
.NET Articles

Common Type System

© 2006 Wiley Publishing Inc.

Memory Layout

Let’s briefly consider the memory layout for objects and values. It should help to illustrate some of the fundamental differences. Consider if we had a class and a struct, both containing two int fields:

class SampleClass
{
   public int x;
   public int y;
}
 
struct SampleStruct
{
   public int x;
   public int y;
}

They both appear similar, but instances of them are quite different. This can be seen graphically in Figure 2-2, and is described further below.


Image:ProNETFramework2-2.jpg
Figure 2-2: Object and value memory layout.


You’ll immediately notice that the size of a value is smaller than that of an object.


Previous_Page_.gif Next_Page_.gif




Personal tools

AbeBooks.com – Textbooks