C++ how to check the access to heap memory

I have the following question. I am not if it is possible and how.
I want understand when the code are using an memory address allocated in heap (for all type of objects built-in and user define).
For example:

char* p= new char[60];
strcpy(p,"home");  // statement A

There is a way to understand that “statement A” is using the address “p” allocated in heap ?
By redefining operator new, I can store the heap addresses but how to understand when some instructions are using them ?
I’d like to do this in transparent way for the user.

Thanks a lot

****** An example

char* p= new char[60];
delete [] p;
strcpy(p,"home");  // statement A

I want warning this invalid memory access.
To do this I must understand that strcpy are trying to access to the address p so i can perform some test on validity of p.

Source: c++

Leave a Reply