Please see the apiExample application for a simple application that demonstrates the usage of the API.
You can find this in the examples folder in the Memory Validator installation directory.
This simple code snippet shows how you might use the API in your application.
This example is for a simplistic cooking machinery that mixes ingredients and bakes them into a cake.
Note that when run on a computer that doesn't have Memory Validator installed these API calls will have no effect, and there are no dependencies upon Memory Validator - you can ship your product with these API calls in it.
#include "svlMVAPI.h"
int main(int argc,
char *argv[])
{
if (mvLoadProfiler())
{
// profiler loaded OK
if (mvStartProfiler())
{
// profiler started OK
// ensure we have data collection turned on (don't call this if you wish to honour the data collection setting in the Memory Validator GUI)
mvSetCollect(TRUE);
}
else
{
// failed to start profiler
}
}
else
{
// failed to load profiler (is Memory Validator installed on the machine?)
}
// place watermarks before and after all major events
// we can then use the watermarks in the GUI to see which parts of the application leak memory
mvSetWatermark(_T("Start"));
doInit();
mvSetWatermark(_T("AddIngredients"));
doAddIngredients();
mvSetWatermark(_T("MixIngredients"));
doMixIngredients();
mvSetWatermark(_T("Bake"));
doBake();
mvSetWatermark(_T("Cool"));
doCooldown();
mvSetWatermark(_T("Shutdown"));
doShutdown();
mvSetWatermark(_T("End"));
}