最大内存一个.NET进程可以分配 [英] Maximum Memory a .NET process can allocate

查看:227
本文介绍了最大内存一个.NET进程可以分配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是最大的内存垃圾收集器分配给一个.NET过程?当我编译到x64,Process.GetCurrentProcess.MaxWorkingSet返回有关1,4GB,但是当我编译成值为anycpu(64)相同数量被返回。对于x64它应该更像是显示在任务管理器中的限制的价值。我怎样才能得到正确的数量在所有情况下超过时,会导致内存溢出,异常?

What is the maximum memory the garbage collector can allocate for a .NET process? When i compile to x64, Process.GetCurrentProcess.MaxWorkingSet returns about 1,4GB, but when i compile to AnyCPU (x64) the same number is returned. For x64 it should be more like the "Limit" value that is displayed in the Task Manager. How can i get the correct number that will cause OutOfMemory-Exceptions when exceeded in all cases?

一些例子是什么方法应该返回:

Some examples what the method should return:

1)机器配置:x64的Windows中,4GB的物理内存,4GB页面文件
- 作为64位进程:8GB
-As 32位进程:1.4GB

1) Machine Configuration: x64-Windows, 4GB physical memory, 4GB page file
-As 64-Bit process: 8GB
-As 32-Bit process: 1.4GB

2)机器配置:64位Windows的,1GB物理内存,2GB的页面文件
- 作为64位进程:3GB
-As 32位进程:1.4GB

2) Machine Configuration: x64-Windows, 1GB physical memory, 2GB page file
-As 64-Bit process: 3GB
-As 32-Bit process: 1.4GB

3)机器配置:X32-的Windows,4GB的物理内存,4GB页面文件
-As 64位进程:不会发生
-As 32位进程:1.4GB

3) Machine Configuration: x32-Windows, 4GB physical memory, 4GB page file
-As 64-Bit process: Won't happen
-As 32-Bit process: 1.4GB

4)机器配置:X32-的Windows,512MB的物理内存,512MB的页面文件
-As 64位进程:不会发生
-As 32位进程:1.0GB

4) Machine Configuration: x32-Windows, 512MB physical memory, 512MB page file
-As 64-Bit process: Won't happen
-As 32-Bit process: 1.0GB

推荐答案

Windows可以被配置为需求分配多页文件空间,或<一href="http://windowshelp.microsoft.com/Windows/en-GB/help/89ca317f-649d-40a6-8934-e5707ee5c4b81033.mspx">on申请。
<一href="http://msdn.microsoft.com/en-us/library/system.activities.design.base.propertyediting.editorreuseattribute%28VS.100%29.aspx">Job对象可以prevent超过一定量的存储器的消耗。
堆和它的代性质的碎片(加上需要投入大量的东西在大对象堆)

Windows can be configured to allocate more page file space on demand, or on request.
Job objects can prevent the consumption of more than a certain amount of memory.
Fragmentation of the heap and the generational nature of it (plus the need to put large stuff in the Large Object Heap)

所有这些意味着硬限制是不是在现实中多大用处,并指回答有多少内存可能我在理论上分配的,而更复杂的比你想象的。

All these mean that the hard limit is not much use in reality and means answering the question "how much memory could I theoretically allocate" is rather more complex than you think.

既然是复杂的人的要求的这个问题可能是试图做一些事情的错误的与他们的问题应该重定向到更有用的东西。

Since it is complex anyone asking that question is probably trying to do something wrong and should redirect their question to something more useful.

什么是你想这样做,似乎必要这样的问题?

What are you trying to do that would appear to necessitate such a question?

我只是想知道什么时候该进程的当前内存负载能拿问题   所以我可以像释放自定义缓存的一些项目的动作。

"I just want to know when the current memory load of the process could get problematic so I can take actions like freeing some items of a custom cache."

右键。这是更容易处理的问题。

Right. this is much more tractable a question.

两种解决方案,以复杂的:

Two solutions in order of complexity:

  1. 请您缓存使用在WeakReferences
    • 这意味着事情会被系统释放几乎奇迹般地为你,但你无法控制的事情,如替换策略
    • 在这依赖于缓存的数据比键和弱引用
    • 的开销更大
  1. Make your caches use WeakReferences
    • This means that things will be freed by the system almost magically for you but you will have little control over things like the replacement policy
    • this relies on the cached data being much bigger than the key and the overhead of a weak reference
  • 这可以让你把释放东西的控制权。
  • 您有依赖的GC几代这可能需要一段时间才能到稳定状态的适当的最大规模​​的系统上。

注意要点。 它是的真正的维持这个庞大的高速缓存(将硬盘通过它的声音),而不是重新计算/重新请求的数据。 如果缓存具有常用/连续请求的项目那么多的努力将花费寻呼数据和输出之间的地区差。一个有效的调整relpacement政策较小的高速缓存站在执行好得多(并与其他正在运行的程序太大的​​影响较小)

Points to note. Is it really less expensive to maintain this massive cache (going to disk by the sounds of it) than to recalculate/re-request the data.
If your cache exhibits poor locality between commonly/consecutively requested items then much effort will be spent paging data in and out. A smaller cache with an effective tuned relpacement policy stands a good chance of performing considerably better (and with much less impact on other running programs)

顺便说一句:在.NET中,没有可变大小的对象(字符串,数组)可以大于2GB更多的大小,由于核心CLR结构的内存管理的限制。 (以上任何一种解决方案将受益于这一点)

As an aside: In .Net, no variable sized object (strings, arrays) can be more than 2GB in size due to limitations of the core CLR structures for memory management. (and either solution above will benefit from this)

这篇关于最大内存一个.NET进程可以分配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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