Friday, July 9, 2010

QubLib Smart Pointers Won't Be Quite As Smart

So, it's always a let down when you think you make a breakthrough on something just to find out that you forgot something that is vital to your development. My last post was about determining whether a pointer points to the stack or the heap. I thought I had found a way to determine this in a way that was independent to the hardware or OS of the machine, but when I tried it again on my Windows and Linux machines, I found that my Windows machine gave me some issues. My simple way of finding where the top of the stack is and then finding the direction it is growing in didn't quite work on Windows as I had hoped. So, I decided that I would try and have a function run before the main function is called (a constructor of a global variable), but then I thought that it won't be the exact beginning of the stack, because it is possible that another global variable constructor could be called that will point to an object that is lower on the stack than my variable that I was hoping would be the first variable on the stack. Grrr.... I was okay to live with that potential problem, but then I thought of one thing that just brought the entire concept crashing down. What would happen if I pointed a QubLib Smart Pointer at a static variable or a global variable? At this point, I realized I was attacking this problem from the wrong point of view. It's like trying to figure out whether a balloon is red by saying, "Is it blue? No huh? How about yellow? Purple? Lime Green? Neon Pink? ..." If you are trying to exhaust all of the possible things it is not just to figure out if it is red, then there will always be another color that you haven't thought of. However, if I could find a way to say, "Hey, is the ballon red?" or in my case, "Hey is this address on the heap?" then my problems would be solved. But, since I don't know how to do that, I guess for now QubLib Smart Pointers will just have to have a disclaimer: "Don't point at anything that is not in the heap. End of Story."

1 comment:

  1. I imagine you ran into this during your internet-searching, but I found it interesting: