MemoryScape intercepts calls made by your program to heap library functions that allocate and deallocate memory by using the
malloc() and
free() functions and related functions such as
calloc() and
realloc(). The technique it uses is called
interposition. MemoryScape’s interposition technology uses an agent routine to intercept calls to functions in this library. This agent routine is sometimes called the Heap Interposition Agent (HIA).
You can use MemoryScape with any allocation and deallocation library that uses such functions as
malloc() and
free(). Typically, this library is called
the malloc library. For example, the C++
new operator is almost always built on top of the
malloc() function. If it is, MemoryScape can track it. Similarly, if your Fortran implementation use
malloc() and
free() functions to manage memory, MemoryScape can track Fortran heap memory use.
After the agent intercepts a call, it calls the original function. This means that you can use MemoryScape with most memory allocators.
Figure 5 shows how the agent interacts with your program and the heap library.
Because MemoryScape uses interposition, memory debugging can be considered non-invasive. That is, MemoryScape doesn’t rewrite or augment your program’s code, and you don’t have to do anything in your program. Because the agent lives in the user space, it will add a small amount of overhead to the program’s behavior, but it should not be significant.