C#/ .Net框架中的堆大小 - 可以增长吗? [英] Heap size in C# / .Net Framework - Can it grow and how?

查看:193
本文介绍了C#/ .Net框架中的堆大小 - 可以增长吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的一本大学书籍中遇到了一个令人困惑的问题:
这里说堆不是静态的,并且可以通过从操作系统请求更多内存来根据需要增长。 p>

所以我困惑的是:假设我运行我的应用程序,并且对象被分配在堆上。在某些时候,应用程序内存不足:现在会发生什么?

据我所知,Gc(垃圾收集器)开始并开始它的标记和扫描操作。我想知道是不是由CLR调用Gc,是否有任何可能让堆从操作系统请求更多的内存?

我在C ++语言中读到,有一种方法可以实现这一点,但在C#.Net Framework 4.5中是否可能?


<在.NET中的堆是内存的一部分,对于实际用途,对于32位进程可以达到大约1.5GB的最大值,对于64位(无限制)再次,为了实际的目的),它确实会根据需要从操作系统请求内存。然而,由于过多的碎片和大量分配的使用,它可能会耗尽内存 - GC不会压缩大型对象堆。



当您在C ++中使用它时完全控制你如何制定内存分配策略,在.NET中完成你的工作,而且你对于如何完成这些工作几乎没有发言权,尽管大多数情况下它确实做得很好。


I've encounterd a confusing matter written in one of my college books: It is stated there that "The heap is not static and can grow as needed by requesting more memory from the operating system".

So what I'm confused about is the following: Suppose I run my application, and objects are allocated on the heap. At some point, the application runs out of memory: what happens now?

From what I understand, Gc (Garbage collector) kicks in and begins it's mark and sweep operations. I wonder if somehow, instead of invoking the Gc by the CLR, is there any possibility for the heap to request more memory from the operating system?

I read that in C++ language, there is a way to achieve that, but is it possible in C# .Net Framework 4.5?

解决方案

The heap in .Net is a portion of memory that for practical purposes can reach a maximum of around 1.5GB for 32-bit processes and unlimited for 64-bit (again, for practical purposes), and it will indeed request memory as needed from the OS. However it may run out of memory due to excessive fragmentation and use of large allocations - the GC won't compact the large object heap.

When you do it in C++ you have total control on how you want to strategize memory allocation, in .NET that is done for you, and you have very little say on how that is done even though for the most part it does a damn good job.

这篇关于C#/ .Net框架中的堆大小 - 可以增长吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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