简体   繁体   中英

Programmatically find how much RAM available

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 (ie 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).

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.

PS 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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