.NET-函数变量存储在地址空间中的堆或堆栈上? [英] .NET - Function variables stored on heap or stack in address space?
问题描述
我在考试中遇到以下问题:
I encountered the following question in an exam:
当程序调用函数时,其中的数据结构类型为 在该函数中为变量分配的内存?
When a program calls a function, in which type of data structure is the memory allocated for the variable in that function?
- HEAP
- 队列
- LIFO
- 堆栈
- HEAP
- QUEUE
- LIFO
- STACK
根据测试,尽管我选择了堆栈,但HEAP是正确的答案.
According to the test, HEAP is the correct answer, although I selected STACK.
外面有一个很棒的人可以解释为什么吗?
Can someone fantastic person out there please explain why?
谢谢.
推荐答案
好,局部变量和参数存储在堆栈上,而不是堆上.对于局部值类型,这意味着值本身存储在堆栈中.对于本地引用类型,只有引用会在堆栈中.
Well, local variables and parameters are stored on the stack not on a heap. For local value-types, this means that the value itself is stored on the stack. For local reference-types, only the reference will be on the stack.
但要获得更深入的解释,我建议阅读Erik Lippert的一篇非常好的博客文章(他已经在评论中指出了此博客文章):
Yet to get a more in-depth explanation I recommend to read a very good blog post of Erik Lippert's (who has already pointed to this blog post in the comment): The Stack Is An Implementation Detail, Part One .
这篇关于.NET-函数变量存储在地址空间中的堆或堆栈上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!