after allocating memory from new or whatever always check to see if the pointer is not null
Object * foo = new Object();if (!foo) handleOutofMemoryError();
also anytime you are retrieving pointers and running functions you should be checking for null.
Object * obj = getObjectFromSomewhere();if (!obj) handleNullPointerReturned();
never assume that pointers you are retrieving are good. it's always possible, esp as your code gets more complex, that you will delete a pointer and then in some other thread, ask for that variable. I'd also get into the habit of setting pointers to NULL after you delete them. otherwise you can be accessing a valid memory space but your object isn't really there. also, always check for NULL when calling delete:
if (objPtr) delete objPtr;objPtr = NULL;
and finally always initialize pointers to NULL so they aren't filled with junk data that could also point to valid memory space when it shouldn't:
//class constructorObject::Object(){ memberVarPtr = NULL;}//in a functionvoid main(){ Object * obj = NULL;}
so yeah, any access violation errors almost always mean you have a bad pointer.
-me
[edited by - Palidine on January 16, 2004 3:13:26 PM]