Intel® C++ Compiler Classic Developer Guide and Reference

ID 767249
Date 12/16/2022
Public

A newer version of this document is available. Customers should click here to go to the newest version.

Document Table of Contents

Checking Custom Memory Allocators

The pointer checker is not supported on macOS systems.

Many C and C++ applications use standard memory allocation functions to allocate large chunks of memory and then define their own custom memory allocation functions to allocate these large chunks of memory into smaller chunks. If you use the pointer checker on a module that contains custom memory allocation functions, every memory allocation from these custom functions will have the bounds information from the large chunk of memory.

To create the correct bounds information for a pointers in a custom memory allocator function, use the __chkp_make_bounds() intrinsic function.

For example, consider the case where you create a custom memory allocator function that returns a pointer. To add the exact bounds information to the return pointer, use the __chkp_make_bounds() intrinsic function in the return value:

Adding exact bounds information to a return pointer

void *myalloc(size_t size) {
	  // Code to do allocate the large chunk of memory into small chunks.
	  // Add bounds information to the pointer
   return __chkp_make_bounds(p, size);
}

NOTE:

If you override the new operator in C++, you can use the same technique to give bounds information to the return pointer.