You can easily check in your overloaded new operator. Be sure to implement all the tastes of the new operator (as AProgrammer already pointed out).
Calling the original / default new is not possible, but it is not difficult to complete. In the end, the new only highlights the memory that it is. Therefore, instead of calling the original / default, you can also call malloc, HeapAlloc, or any memory allocation procedure found on your system. Be sure to call the appropriate memory deletion method (free, HeapFree, ...) in your delete implementation.
You did not say what condition you are going to check in your implementation? If this is a βstaticβ condition (I mean: always giving the same result at runtime of your application), then the same condition should be added to your removal implementation.
If the condition depends on the situation and changes when the application is launched, you should foresee a method in which you can find out which implementation of deletion is used in your delete function. One trick does the following:
In your implementation of the new:
- allocate 8 bytes more than requested (this should be 8 bytes to keep alignment correct)
- enter the first 8 bytes with identification so that you can find out what basic memory allocation function you used
- add 8 bytes to the highlighted pointer and return this
In your implementation of delete:
- subtract 8 bytes of the pointer provided to you
- check the identification found in this place (see new) to see what type of base implementation-deletion you should name
source share