Possible Duplicate:
Why value-types are stored onto Stacks?
I understand about boxing / unboxing but my question is why .NET make the choice of store ie. an integer in stack ?
Its logical when you are (simple) passing parameters between procs / functions... but... why...is this generallly used in .NET in an开发者_StackOverflow社区y case ?
Thanks a lot!
Not all integers are in stack.only integers which are local to functions or passed between functions are stored in stack.
If the integer is a part of class(ref type) then the integer is stored on the place where the ref types are stored(managed heap)
Because allocating heap objects for every integer and dereferencing the pointers all the time would be orders of magnitude too slow.
精彩评论