Background and motivation
The System.Environment class has many useful properties regarding the environment where the process runs, but it doesn't currently have properties about the total and free amount of physical and virtual memories. These are very important metrics, especially for computation-intensive projects like ML.NET's machine learning.
It would be great if the Environment class would have more properties describing the total and free amounts of physical and virtual memories.
API Proposal
namespaceSystem{publicstaticpartialclassEnvironment{publicstaticlong?TotalPhysicalMemory{get;}publicstaticlong?FreePhysicalMemory{get;}publicstaticlong?TotalVirtualMemory{get;}publicstaticlong?FreeVirtualMemory{get;}}}API Usage
// Get the total physical memory (in bytes)vartotalRam=Environment.TotalPhysicalMemory;// Get the total physical memory (in bytes)varfreeRam=Environment.FreePhysicalMemory;// Get the total physical memory (in bytes)vartotalVM=Environment.TotalVirtualMemory;// Get the total physical memory (in bytes)varfreeVM=Environment.FreeVirtualMemory;
Alternative Designs
if(OperatingSystem.IsWindows()){ObjectQuerywql=newObjectQuery("SELECT * FROM Win32_OperatingSystem");ManagementObjectSearchersearcher=newManagementObjectSearcher(wql);ManagementObjectCollectionresults=searcher.Get();foreach(ManagementObjectresultinresults){ulongtotalVisibleMemorySize=(ulong)result["TotalVisibleMemorySize"];ulongfreePhysicalMemory=(ulong)result["FreePhysicalMemory"];ulongtotalVirtualMemorySize=(ulong)result["TotalVirtualMemorySize"];ulongfreeVirtualMemory=(ulong)result["FreeVirtualMemory"];}}Risks
It's not a risk per say, but these new properties would require some extra work, because we would need to call platform-specific APIs. Virtual memory is used on Windows, Linux, Android and iOS, so the appropriate APIs should be available on those, but I'm not sure about others that .NET supports.
I would define these new properties as nullable types, because I can image that some .NET supported operating system doesn't support these reports regarding memory usage.
Also, if it's not implemented on a specific platform, they could return null.
Background and motivation
The System.Environment class has many useful properties regarding the environment where the process runs, but it doesn't currently have properties about the total and free amount of physical and virtual memories. These are very important metrics, especially for computation-intensive projects like ML.NET's machine learning.
It would be great if the Environment class would have more properties describing the total and free amounts of physical and virtual memories.
API Proposal
API Usage
Alternative Designs
Risks
It's not a risk per say, but these new properties would require some extra work, because we would need to call platform-specific APIs. Virtual memory is used on Windows, Linux, Android and iOS, so the appropriate APIs should be available on those, but I'm not sure about others that .NET supports.
I would define these new properties as nullable types, because I can image that some .NET supported operating system doesn't support these reports regarding memory usage.
Also, if it's not implemented on a specific platform, they could return null.