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.