简体   繁体   English

c#为虚拟机分配内存

[英]c# allocating memory to the virtual machine

C#是否具有相当于java的-Xmx1024m开关,允许您增加对虚拟机的内存分配?

No. The CLR handles memory allocation very differently than java in this regard. 在这方面,CLR处理内存分配与java非常不同。 It will continue to increase the heap size, with no upper limit (other than architectural limits). 它将继续增加堆大小,没有上限(除了体系结构限制)。

On a 64bit Operating System, while targetting x64, the CLR will continue to allow a process to allocate memory up to the total memory available in the system. 在64位操作系统上,当针对x64时,CLR将继续允许进程分配内存,直至系统中可用的总内存。 There is no fixed upper limit artificially imposed on a process. 人工过程没有固定的上限。

On a 32bit system, or when targetting x86, the practical upper limit tends to be between 1.2 and 1.6 GB. 在32位系统上,或者在针对x86时,实际上限往往在1.2到1.6 GB之间。 At this point, you will start running into out of memory exceptions. 此时,您将开始遇到内存不足异常。 (Theoretically, it should use 2GB, but the CLR itself takes up some space, and the way it handles memory addressing causes the Out of memory errors to occur in this range instead.) (理论上,它应该使用2GB,但CLR本身会占用一些空间,而它处理内存寻址的方式会导致内存不足错误发生在此范围内。)


Edit: Here's a good article describing the differences in how memory is handled in the JVM and the CLR . 编辑:这是一篇很好的文章,描述了在JVM和CLR中处理内存的方式差异 I believe the main reason the JVM requires the use of -Xmx is because it does not release memory back to the operating system. 我认为JVM需要使用-Xmx主要原因是它不会将内存释放回操作系统。 It therefore provides a way to limit the memory consumption of a program. 因此,它提供了一种限制程序内存消耗的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM