C
Chris Thomasson
But you can't check whether a pointer is valid; you just have to
know. (I agree that it would be nice if pointers had an
isValid() member function, but they don't.)
What would an `isValid()' function be checking for exactly? If the pointer
is NULL, if the pointer points to an object which exists in non-freed
memory, or all of that? Would it be similar to the following obsolete Win16
functions:
IsBadCodePtr()
IsBadReadPtr()
IsBadStringPtr()
IsBadWritePtr()
AFAICT, in a multi-threaded environment any "isValid" function which works
on pointers has some associated race-conditions. For instance, if Thread A
calls `isValid()' on pointer P which succeeds, and Thread B immediately does
something which invalidates P, well, Thread A will operate on the false
assumption that P is valid when B just invalided it under its nose; that
would be bad.