Memory Allocation APIs
Intel® VTune™
provides a set of APIs to help it identify the semantics of your
Profiler
malloc
-like heap management functions.
Annotating your code with these APIs allows
VTune
to correctly determine memory objects as part of
Memory Access Analysis.
Profiler
Usage Tips
Follow these guidelines when using the memory allocation APIs:
- Createwrapperfunctions for your routines, and put the__itt_heap_*_beginand__itt_heap_*_endcalls in these functions.
- Allocate a unique domain for each pair ofallocate/freefunctions when calling__itt_heap_function_create. This allows theVTuneto verify a matchingProfilerfreefunction is called for everyallocatefunction call.
- Annotate the beginning and end of everyallocatefunction andfreefunction.
- Call all function pairs from the same stack frame, otherwise theVTuneassumes an exception occurred and the allocation attempt failed.Profiler
- Do not call anendfunction without first calling the matchingbeginfunction.
Using Memory Allocation APIs in Your Code
Use This
| To Do This
|
---|---|
| Declare a handle type to match
begin and
end calls and
domains.
|
| Identify allocation functions.
|
| Identify deallocation functions.
|
| Identify reallocation functions.
Note that
itt_heap_reallocate_end() must be called after the attempt even if no memory is returned. VTune
assumes C-runtime
Profiler realloc semantics.
|
Usage Example: Heap Allocation
#include <ittnotify.h>
void* user_defined_malloc(size_t size);
void user_defined_free(void *p);
void* user_defined_realloc(void *p, size_t s);
__itt_heap_function my_allocator;
__itt_heap_function my_reallocator;
__itt_heap_function my_freer;
void* my_malloc(size_t s)
{
void* p;
__itt_heap_allocate_begin(my_allocator, s, 0);
p = user_defined_malloc(s);
__itt_heap_allocate_end(my_allocator, &p, s, 0);
return p;
}
void my_free(void *p)
{
__itt_heap_free_begin (my_freer, p);
user_defined_free(p);
__itt_heap_free_end (my_freer, p);
}
void* my_realloc(void *p, size_t s)
{
void *np;
__itt_heap_reallocate_begin (my_reallocator, p, s, 0);
np = user_defined_realloc(p, s);
__itt_heap_reallocate_end(my_reallocator, p, &np, s, 0);
return(np);
}
// Make sure to call this init routine before any calls to
// user defined allocators.
void init_itt_calls()
{
my_allocator = __itt_heap_function_create("my_malloc", "mydomain");
my_reallocator = __itt_heap_function_create("my_realloc", "mydomain");
my_freer = __itt_heap_function_create("my_free", "mydomain");
}