I’m wondering if it’s possible to determine if a given address is on the stack or in the heap. I’d like this because a reference counting system we use has a flaw that if a smart pointer is somehow pointed at an object on the stack, bad things can happen. If I had this functionality, I could use it to detect this error condition early and throw so that the developer doing this would be forced to deal with this immediately.
Share
Any solution would have to be platform specific. In Windows, you can use HeapWalk to enumerate all chunks of memory in the heap. In Unix, you can try to use pthread_attr_getstack().