Developer Guide and Reference

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); }
If you override the
new
operator in C++, you can use the same technique to give bounds information to the return pointer.
<