Reputation: 703
Traditionally I have used the CRT memory reporting functions like this:
_CrtMemState state[3];
_CrtMemCheckpoint(&state[0]);
foo();
_CrtMemCheckpoint(&state[1]);
int const diff = _CrtMemDifference(&state[2], &state[0], &state[1]);
_CrtMemDumpStatistics(&state[2]);
More recently I have used Visual Studio's builtin heap profiling tool with snapshots. Create first snapshot before foo(), second snapshot after foo(), then look at the diff output.
Now I used both at the same time and compared the results. I expected both results to be pretty much the same, if not exactly the same. But this is not the case. Memory sizes vary wildly. The only thing they share is the number of allocations. I don't know what to make of this. How should I interpret those results? What causes the difference? Whom should I trust?
Note that the CRT results are the same indepedently of heap profiling being enabled or not.
Upvotes: 0
Views: 171
Reputation: 703
So it seems that memory profiling is neither an exact science nor a very popular one.
Short answer to my own question: Just pick any type of measurement, then stick with it and compare the abstract numbers for every measurement you take. But never start wondering what those numbers could mean.
FYI, here's what I explored:
In the end, I used _CrtMemCheckpoint, _CrtMemDifference and _CrtSetAllocHook in debug, because I felt that I could interpret those numbers. However, these functions are not available in release, so I used GetProcessMemoryInfo there. Had no clue how to interpret those numbers, but everytime they went down because of my optimizations, they gave me a happy face.
Upvotes: 0