Possible Duplicate:
Where are .NET local variables stored?
function storeonstack()
{
int a;
int b;
int c;
a=1;
b=1;
a=2
c=2;
}
Can Some body explain me how these value types are stored on stack?
Possible Duplicate:
Where are .NET local variables stored?
function storeonstack()
{
int a;
int b;
int c;
a=1;
b=1;
a=2
c=2;
}
Can Some body explain me how these value types are stored on stack?
Practically speaking*, value types are stored on the stack if they are local variables within a method, or on the heap if they are members of a reference type. Sometimes, local variables may also be stored on the heap if they are included in a closure. This is required so that the variables can continue to live after the function exits (and the stack frame is cleaned up). Local variables may also be stored in registers when they are used in operations, before being spilled back to the stack. Depending on JIT optimizations, local variables may only exist in registers, or may not exist at all. Member variables should always exist, though.
*Yes, technically, there's no guarantee that things like stack and heap exist, but let's be honest, on most, if not all, .NET implementations, there is a stack and a heap as in C programs.
It is an implementation detail and depends upon compiler. It may vary from compiler to compiler.