c# allocating memory to the virtual machine
Does C# have an equivalent of java's -Xmx1024m switch that allows you 开发者_如何学JAVAto increase memory allocation to the virtual machine?
No. The CLR handles memory allocation very differently than java in this regard. 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. 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. 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.)
Edit: Here's a good article describing the differences in how memory is handled in the JVM and the 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. It therefore provides a way to limit the memory consumption of a program.
精彩评论