Friday, August 06, 2004

VJs Tip Of The Day - August 6th 2004

Common Type System - Value Types vs Reference Types

Value Types and Reference Types are two basic types of CTS... Value Types are allocated on the stack and Reference Types are allocated on Managed heap... How this thing works is that the value of the "Value Types" is allocated on the stack where as in case of "Reference Types" the value i.e. the object itself resides in the heap but there is a pointer to the object in the memory...

Considering this differences value types are faster but consume the process memory....
"Reference types don't consume this process memory but then they become slower... When value types are copied then the value is copied as a whole on the stack, when reference types are copied then only the references are copied on the stack..., when to use Reference Types as compared to Value Types and visa-versa is based on various other factors also so do take time to decide when to use what..."
Value types are usually native data types like int, float, char, enums etc... Reference types mostly include string, classes and some other user defined types...

PS: I wrote Value types to be allocated on heap in my second paragraph only Kathleen was able to find that out... You guys do write back when you see such gross errors... Thanks Kathleen...

No comments: