Please enable JavaScript to view this site.

Memory Validator Help

Navigation: Tag Tracking

Data Tracking with svlDataTracker

Scroll Prev Top Next More

 

Tag trackers allow allocations to be marked with a tag that can later be used to filter allocation events.

 

 

Examples of using tag trackers in code

 

Here's a simple example function using tag trackers:

 

void exampleFunc()
{
   int   i;
 
   for(i = 0; i < getNumWorkUnits(); i++)
   {
      svlDataTracker   trackWorkUnits("workunit"); // Set current tracker to be 'workunit'
 
      processWorkUnits(i);
   }
}

 

In this example all memory allocations, reallocations and deallocations that happen inside processWorkUnits() have the tag workunit.

 

In the more complex code fragment below, three tags are used to classify the actions of the functions called.

 

Note that when the Flowers tracker starts, the Cats tracker is temporarily suspended, to be resumed when the Flowers tracker falls out of scope.

 

   createAFish("Pike");                   // no tracker
 
   {
      svlDataTracker   tracker_cats("Cats");
 
      createAnAnimal("Lion");             // cats tracker
      createAnAnimal("Tiger");            // cats tracker
      createAnAnimal("Panther");          // cats tracker
 
      {
         svlDataTracker   tracker_flowers("Flowers");
 
         createAFlower("Daffodil");       // flowers tracker
         createAFlower("Rose");           // flowers tracker
 
         {
            svlDataTracker   tracker_trees("Trees");
 
            createATree("Oak");           // trees tracker
            createATree("Sycamore");      // trees tracker
            createATree("Ash");           // trees tracker
            createATree("Horse Chestnut");// trees tracker
         }
 
         createAFlower("Lily");           // flowers tracker
      }
 
      createAnAnimal("Leopard");          // cats tracker
      createAnAnimal("Cheetah");          // cats tracker
      createAnAnimal("Cougar");           // cats tracker
   }
 
   createAFish("Salmon");                 // no tracker

 

 

svlDataTracker class usage

 

The svlDataTracker class used in the examples above is defined in svlDataTracker.h and svlDataTracker.cpp which should be in the API folder of the Memory Validator installation directory.

 

The class is written so as not to include any dependencies on Memory Validator into your application.

 

The class will only activate the Memory Validator functionality if using Memory Validator with your application, and otherwise does nothing.

 

To use svlDataTracker in your application:

 

#include svlDataTracker.h into each file you will be using svlDataTracker
 

use the svlDataTracker class as shown above

 

note Do not dynamically create svlDataTracker objects as this will break the tag scoping rules and make them behave unpredictably.

 

 

Not using C++?

 

If you're not using C++, here's a couple of options:

 

An object oriented solution

 

If you're using an object oriented language such as Delphi you can create a Delphi equivalent to svlDataTracker.

 

You'll find the source code for svlDataTracker in svlDataTracker.cpp and this should be easy enough to understand for you to be able to create a suitable implementation for your object orientated language.

 

An API solution

 

The C++ and object orientated solutions both use the Memory Validator API.

 

You can also link your own program with the Memory Validator stub, and use the API directly.

 

The API provides two functions (among others) exported from svlMemoryValidatorStub.dll:

 

mvPushTracker(char *trackerName) instructionStep pushes a tag tracker on to the tag stack, making it the 'current' tag
 

mvPopTracker() instructionStep pops the current tag tracker from the top of the tag stack, making the next one (if any) current

 

 

You can find out more about the API solution for tag tracking as well as other API functions in these topics:

 

The Native API

 

Calling the API functions using GetProcAddress
 

Calling the tag tracker functions above