I want to find out what libraries are using the most memory. I want to make a kind of memory logger in my application. This needs to look up programmatically how much memory is used by what libraries in its own process.
For example, I have a program that is using 10MB of memory, there is a .dll in there that is using 9MB of memory. I would like to see all the dll’s and how many memory they use.
This application is going to run on Windows. Everything needs to be done programmatically.
Not sure if it is the simplest approach, but maybe you should hook memory allocation WinAPI functions right after loading each library.
Then in your hook you will be able to do necessary counting
Take a look at Microsoft Detours library as a good hooking framework (http://research.microsoft.com/en-us/projects/detours/). It is generally not free, but is available for free “for research, non-commercial, and non-production use”
Which actual functions to hook actually depends on the dlls that need to be tracked.
If all of them are compiled with MSVC runtimes linked dynamically you’d have to hook malloc() / free() / calloc() / realloc() series of functions.
If it was linked statically against runtime, or was not compiled with MS VC, you’ll have to hook memory-related WinAPI calls such as HeapAlloc / HeapCreate / HeapDestroy / HeapFree / heapReAlloc / VirtualAlloc / VirtualFree (I just looked for memory-related functions that msvcr100.dll imports from kernel32.dll)