我可以(而且我曾经想)设置在.net中的最大堆大小? [英] Can I (and do I ever want to) set the maximum heap size in .net?

查看:286
本文介绍了我可以(而且我曾经想)设置在.net中的最大堆大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我来自一个Java背景,我习惯说的是什么JVM的最大堆大小应该的事情之一。如果正在运行的程序试图吞下多是允许的,而垃圾收集器无法释放更多的资源,那么OutOfMemoryError异常被抛出,这一切都一声巨响。因此,设置最大堆大小是很重要的Java语言。

Coming from a java background, one of the things I am used to is telling the JVM what the maximum heap size should be. If the running program tries to swallow more than is allowed, and the garbage collector cannot free any more resources, then OutOfMemoryError is thrown and it all goes bang. So setting the maximum heap size is important in Java.

这是否适用于.NET?你能设置堆大小限制?是否CLR只是不停,直到达到机器的物理极限扩大其堆?或者是不是在.net中的一些微妙的原因,一个问题,我的Java眼罩看见?

Does this apply in .net? Can you set the heap size limits? Does the CLR just keep growing its heap until it reaches the machine's physical limits? Or is it not an issue in .net for some subtle reason that my Java blinkers stop me from seeing?

推荐答案

您不能设置最大堆大小的.NET。

You can't set max heap size in .Net unless you host the CLR yourself in a process.

编辑: 为了控制CLR的内存分配,包括最大堆大小,您需要使用托管API主办的CLR和专门使用的内存管理接口,一些起动信息可以在这里找到的MSDN杂志,列CLR内向外:CLR宿主API

To control the memory allocations of CLR including the max heap size, you need to use the hosting api to host the clr and specifically use the "Memory manager interfaces", some starter info can be found here MSDN Magazine, column CLR Inside Out : CLR Hosting APIs

编辑:回答你的问题,为什么你要控制内存分配或专门最大堆大小,你通常不希望,但如果您正在编写一个应用程序,如SQL Server或IIS或者一些实时的应用程序,那么你就会有一个pretty的很好的理由,可以控制内存和具体,避免分页,否则CLR本身和操作系统已经做了pretty的好工作你,剩下的就是确保你的应用程序使用最少的资源为工作的事情很好。

to answer you question, why would you want to control the memory allocation or specifically max heap size, you usually don't want to, but if you're writing an application that is like SQL Server or IIS or some real time application then you'd have a pretty good reason to have control over memory and specifically, avoid paging, otherwise the CLR itself and the OS already do a pretty good job for you, and what is left is to ensure your that application uses minimum resources for things to work well.

这篇关于我可以(而且我曾经想)设置在.net中的最大堆大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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