5

On most platforms and with most JVMs you can pre-allocate the heap on start-up by setting the -Xmx and -Xms options (or a variant thereof) to the same size.

Is it possible to do the same with .NET, and if so, how?

trincot
  • 317,000
  • 35
  • 244
  • 286
sam_pointer
  • 75
  • 1
  • 4
  • 1
    Out of interest, why did you want to do this? Before I started working with *java* I was a *.net* developer and during that time never once had to think about it's garbage collector. Now I'm a java developer I constantly have to juggle different `-Xmx` and `-XX:MaxPermSize` settings to keep things running smoothly and find it a real pain. – Mark Booth Aug 17 '12 at 13:35
  • It's good to have a known maximum limit when planning server capacity. I came to this question for the exact opposite reasons as devOps I need to plan/predict memory for the servers especially when we have multiple processes running in them. – SidJ Jul 07 '16 at 01:25

1 Answers1

9

Sadly no it's not, .the NET runtime makes all the decisions about heap size and relative generational sizing for you.

The only thing you can do is switch between the server version of the garbage collector and the workstation one. This gives more aggressive, one GC per core collecting in the server version and a preference for keeping the app responsive in the workstation one.

Paolo
  • 22,188
  • 6
  • 42
  • 49
  • Thankyou. Which GC is the default, and how do you go about configuring a different GC? – sam_pointer Feb 10 '10 at 11:52
  • Workstation is the default. You can switch to the server version by adding a couple of lines to the config: http://blogs.msdn.com/junfeng/archive/2004/07/13/181534.aspx. If you have process explorer you can see which a process is using by finding either mscorwks.dll (workstation) or mscorsvr.dll (server) loaded – Paolo Feb 10 '10 at 11:55