Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically find how much RAM available

Tags:

.net

memory

mono

Is there a portable way, that works on both .Net and Mono on the various supported operating systems, for a program to tell how much RAM (i.e. physical not virtual memory) is available in the machine it's running on?

The context is a program whose memory requirement is "as much as possible please"; it needs to know how much memory it should aim to allocate, while stopping short of going into swap (thereby grinding to a halt and locking up the whole machine).

like image 500
rwallace Avatar asked May 07 '26 03:05

rwallace


1 Answers

There's no portable way to do that. Even more, the system could interpret 'As much as possible' in a number of ways because of the complexity of memory usage. For example the system could make almost entire RAM available to you by simply moving every running process to swap.

P.S. using swap is not the same as locking up the whole machine. Think of it as just a slower type of RAM available to use.


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!