为什么值类型上堆上创建堆栈和引用类型产生的? [英] Why are Value Types created on the Stack and Reference Types created on the Heap?

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

问题描述

编程语言书通常解释值类型在栈上创建和引用类型都在堆上创建的。

我的问题是为什么。

解决方案
  

我的问题是为什么。

为什么他们解释是什么?因为有时候作者不知道任何更好的自己,有时他们懒得好好解释一下吧。事实也较为复杂。

幸运的是,埃里克利珀写了大量解决此问题:

  • <一个href="http://blogs.msdn.com/b/ericlippert/archive/2009/04/27/the-stack-is-an-implementation-detail.aspx">The栈是一个实现细节,第1部分
  • <一个href="http://blogs.msdn.com/b/ericlippert/archive/2009/05/04/the-stack-is-an-implementation-detail-part-two.aspx">The栈是一个实现细节,第2部分
  • 约值类型的真相

虽然我通常会尽量至少包括完整的答案的释义在这里,我不打算这样做,在这里 - 因为解释它的很简单的几乎必然要给出一个误导性的结果。刚去阅读这些博客文章 - 然后一切埃里克写了。这将需要数周时间,但你会很高兴你没有。

Programming language books usually explain that value types are created on the stack, and reference types are created on the heap.

My question is Why.

解决方案

My question is Why.

Why do they "explain" that? Because sometimes the authors don't know any better themselves, and sometimes they're too lazy to explain it properly. The truth it rather more complicated.

Fortunately, Eric Lippert has written extensively around this:

While I would usually try to at least include a paraphrase of the full answer here, I'm not going to do so here - because explaining it very briefly is almost bound to give a misleading result. Just go and read those blog posts - and then everything else Eric has written. It'll take weeks, but you'll be glad you did.

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

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