views:

130

answers:

3

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  A: 

I recommend a profiling tool: dotTrace works really well.

Alan
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
Ah, I misread your question. Sorry!
Alan
+4  A: 

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
Yes! That's it! I was already worried I had to go through PInvoke to get to this.
David Rutten
The Process class has many nice metrics like this - take a look at the docs, and you'll see many of them.
Reed Copsey
+1  A: 

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
Thanks anyway. Much appreciated.
David Rutten