[Gc] Using GC as a pointer registry

Andreas Saebjornsen saebjornsen1@llnl.gov
Mon, 8 Dec 2003 11:45:06 -0800


I'am doing some work where I need to verify if a pointer is valid or not. I 
wonder if it is possible, when GC memory allocators are used, to see if
a pointer is pointing to a valid object or not. I want that to be a query I 
can make to GC. The prototype of  such a function could be 
'bool GCpointerCheck(void*)' where void* is a pointer and does a lookup
in the GC "registry". Here is a trivial example demonstrating 
what I'am looking for:

#include "gc_cpp.h"

class foo : public	gc {
   public:
      foo(){};
      ~foo(){};
};

int main(int argc, char *argv[])
{
    int i = 0;
    foo* fooObj = new foo();
    foo* fooPointer;
    while(true){
          
          if(i == 10){
              i = 0;
              delete fooObj;
              fooObj = new foo();
          }

          if(  GCpointerCheck(fooPointer) != true )
               fooPointer = fooObj;

          i++;
    }
};


Thank you,
Andreas Saebjoernsen