为什么值类型存储到堆栈? [英] Why value-types are stored onto Stacks?

查看:160
本文介绍了为什么值类型存储到堆栈?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么C#preFER堆栈来存储值类型?这是什么设计背后的主要原因是什么?不会叠加R / W操作会处理,萨维?

Why does C# prefer stack to store value types ? What is the primary reason behind this design ? Won't stack R/W operations would be processing-savy ?

或者可能是你能证明别人为什么不呢?

or may be you can justify why not others ?

推荐答案

埃里克利珀讨论这个<一个href=\"http://blogs.msdn.com/ericlippert/archive/2009/04/27/the-stack-is-an-implementation-detail.aspx\">here;首先,这是不正确的值类型存储在堆栈上。他们的有时的是,但不作为:

Eric Lippert discusses this here; firstly, it is incorrect that "value types are stored on the stack". They sometimes are, but not as:


  • 在一类领域

  • 捕获变量

  • 在迭代器块变量

在他们的可以的存储在堆栈上这是其一生建模的一种便捷方式,但它不是的需要的将它们存储在堆栈中。你可以写一个编译器+ CLI,这并不有无的堆栈,例如。

When they can be stored on the stack it is a convenient way of modelling their lifetime, but it isn't required to store them on the stack. You could write a compiler+CLI that doesn't have a stack, for example.

这篇关于为什么值类型存储到堆栈?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆