1

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?

David Rutten
  • 4,610
  • 6
  • 41
  • 69

3 Answers3

4

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;
Reed Copsey
  • 539,124
  • 75
  • 1,126
  • 1,354
1

I recommend a profiling tool: dotTrace works really well.

Alan
  • 44,339
  • 17
  • 112
  • 132
  • What I need is a way for my application to know how much memory it's using at runtime. I'm not looking for a profiling app. Essentially, what I want is the number of Private Bytes used by my process as visible in the Process Explorer / Task Manager. – David Rutten Sep 03 '09 at 23:48
1

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.

Remus Rusanu
  • 281,117
  • 39
  • 423
  • 553