开发者

Why does .NET save simple types (int,..) in stack? [duplicate]

This question already has answers here: Closed 11 years ago.

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜