0

I want to find out during runtime, how much (heap) memory my c++ program is currently using. Can I achieve this by overloading the new/delete operators? Is there a library which provides this functionality?

I know that tools like valgrind can give me a lot of information about my memory usage, but that information is not available during runtime and thus cannot be used by the program.

Background

I am writing a scientific program. I.e., I can assume that the program may use basically all the memory available on the machine on which it is running (or a predefined, fixed amount). I have to deal with large amounts of data which may or may not fit into the available memory. In case of insufficient memory the program may take countermeasures (e.g. store data to disk or recalculate data instead of storing them). To be able to do that I need to track how much memory has been used.

Rowland Shaw
  • 37,700
  • 14
  • 97
  • 166
user2296653
  • 1,151
  • 1
  • 8
  • 17
  • You want only the sum of memory sizes allocated by your program or the actual size of the heap? Both probably differ if allocations are performed in page size units. – cadaniluk Nov 25 '15 at 13:43
  • 1
    Any particular target operating system? – Rowland Shaw Nov 25 '15 at 13:46
  • Ideally I would like to know the total amount of memory used by the program. However, probably only a limited amount of stack memory is used, so the actual size of the heap would probably be what I want to know. – user2296653 Nov 25 '15 at 13:47
  • @RowlandShaw It should be working on Linux distributions. – user2296653 Nov 25 '15 at 13:49

0 Answers0