我可以(并且我曾经想要)在.net 中设置最大堆大小吗?

Can I (and do I ever want to) set the maximum heap size in .net?(我可以(并且我曾经想要)在.net 中设置最大堆大小吗?)
本文介绍了我可以(并且我曾经想要)在.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 是否会不断增长其堆,直到达到机器的物理极限?或者,由于某种微妙的原因,我的 Java 闪烁器让我看不到,这不是 .net 中的问题吗?

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 中设置最大堆大小,除非您自己在进程中托管 CLR.

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 或一些实时应用程序,那么你有一个很好的理由来控制内存,特别是避免分页,否则 CLR 本身和操作系统已经为你做了很好的工作,剩下的是为了确保您的应用程序使用最少的资源来正常工作.

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 中设置最大堆大小吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
quot;Overflowquot; compiler error with -9223372036854775808L(编译器错误-9223372036854775808L(Q;溢出Q))
Visual Studio 2010 ReportViewer Assembly References(Visual Studio 2010 ReportViewer程序集引用)
Weird behaviour when I open a reportviewer in WPF(在WPF中打开报表查看器时出现奇怪的行为)
how do i pass parameters to aspnet reportviewer(如何将参数传递给aspnet report查看器)