On what operating system? If you want to keep track of total memory usage, you'll need a way to determine the size in memory of all code (e.g. application and dynamically linked libraries) and stack, which will vary depending on OS.
For dynamic heap memory usage, you can make your own implementation of new/delete that counts allocated heap memory - this is the approach taken by memory leak detectors. Have a look at VLD which is an open-source memory leak detector for Visual C++.