问题
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