There's almost certainly going to be a better way to do it, for instance you can write your own memory management functions and redirect new/delete/malloc/free/realloc etc to those new routines.

But in any case the stack and heap addresses can be determined simply by taking the address of variables, and of course anything you do in this area is going to be extremely dependent on the exact version of compiler and platform you're using.