Memory usage of DotNET app

强颜欢笑 提交于 2020-01-15 09:39:10

问题


My application (DotNET) runs as a plug-in inside a C++ standalone app that exposes a C++/CLI SDK.

It is very easy for my users to generate large amounts of data and I'd like to offer an abort option if the memory consumption of my plug-in + the base application reaches -say- 90% of the legal maximum.

How can I measure the total memory consumption (ideally for both the managed and unmanaged code) and how do I know how much memory windows allows for the current application?


回答1:


The Process class provides most of this information. I think what you're after would be Process.PrivateMemorySize64.

You should be able to do:

var memoryUsage = Process.GetCurrentProcess().PrivateMemorySize64;



回答2:


GetProcessMemoryInfo and check the PrivateUsage in the PROCESS_MEMORY_COUNTERS_EX.

Update

Obviously I misred the question and though you want the value from the CLI SDK side of the app. In the managed side, you already got the correct answer.




回答3:


I recommend a profiling tool: dotTrace works really well.



来源:https://stackoverflow.com/questions/1376526/memory-usage-of-dotnet-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!