Stack and heap in c#

Possible Duplicate:
What and where are the stack and heap

There is a difference in C# between heap and stack. I've just realized that I always thought that stack is RAM and heap is hard drive. But now I'm not sure if it's correct. If it isn't then what's is the difference if they are stored in one place?


"The stack" (or more precisely the call stack) is automatically managed memory (even in "unmanaged languages" like C): Local variables are stored on the stack in stack frames that also contain the procedures or functions arguments and the return address and maybe some machine-specific state that needs to be restored upon return.

Heap memory is that part of RAM (or rather: virtual address space) used to satisfy dynamic memory allocations ( malloc in C).

Yet, in C# heap and stack usage is an implementation detail. In practice though, objects of reference type are heap-allocated; value type data can both be stored on the stack and on the heap, depending on the context (eg if it's part of an reference-type object).

链接地址: http://www.djcxy.com/p/2256.html

上一篇: 内存,缓冲区和堆栈有什么区别?

下一篇: 堆栈和堆在C#