4

I have looked through GDB documentation, but haven't found anything that works or shows what I need: the maximum amount of memory that is used by my application.

I'm using MinGW-w64 (GCC for Windows) if that's relevant. I'd like something programmatically, not "look in your task manager". Also: my application executes in one go, it doesn't stop or halt anywhere, and I'd like to keep it that way.

Thanks!

rubenvb
  • 74,642
  • 33
  • 187
  • 332
  • Does the approach need to be portable? – bdonlan Feb 05 '11 at 12:25
  • 1
    Would WMI be an option for you? It could certainly tell you almost anything you need about any process: http://msdn.microsoft.com/en-us/library/aa394582(v=vs.85).aspx – alex Feb 05 '11 at 12:26
  • @bdonlan: Well, I'm kind of surprised gdb doesn't have the capability to sum up the amount... Portable would be better, and external to the application itself would be preferred (no source code contamination). @alex: That's a bit heavy for a simple number of MBs, no? And I'd like to have a existing app report this, so I don't have to screw around with my own implementation. – rubenvb Feb 05 '11 at 12:40
  • Check out this question: http://stackoverflow.com/questions/413477/is-there-a-good-valgrind-substitute-for-windows – Emile Cormier Feb 05 '11 at 14:52

3 Answers3

1

You could wrap malloc/free or new/delete: How-to-profile-memory-usage-of-a-c-program

Thereby you can check how much memory (heap) you are using at any time.

Community
  • 1
  • 1
AndreasT
  • 9,417
  • 11
  • 46
  • 60
0

Windows provides functions to return how much memory is being used.

http://msdn.microsoft.com/en-us/library/aa366589(v=VS.85).aspx

Puppy
  • 144,682
  • 38
  • 256
  • 465
0

The standard doesn't specify anything deeper than malloc() and free(), which leaves C libraries free to implement them to work in their target environments. The result is that a debugger like GDB that isn't tied to a specific environment will have no insight into memory allocation.

Blrfl
  • 6,817
  • 1
  • 25
  • 25
  • But surely the OS knows what resources are tied to a specific resource, and GDB can control the execution of a program to the combined effect of monitoring these resources? Or do I want too much? – rubenvb Feb 05 '11 at 14:24
  • The short answer is that understanding how a process manages its memory management is not GDB's bailiwick and the reasons why could be the subject of a very long article. When GDB wants to allocate memory in the process being debugged (which it does), it calls whatever allocator is linked into it and doesn't care about what happens inside. Total memory is allocated isn't really a debugging function; it's something the OS has to worry about. – Blrfl Feb 05 '11 at 15:49