I would be very careful about relying on routines like PrvPtrCheck -- either directly or indirectly (via cloning their behavior). When/if the OS changes the way it handles memory, you will be in a very deep hole.
A much more robust method is to check the memory when it is allocated. That is, routines like MemPtrNew and MemHandleNew have very clear and well-documented behavior when they fail (both return 0). Just check those return values and do appropriate error handling then. True, if the pointer was gotten from the stack, (say as the address of a local variable), this approach won't work (but PrvPtrCheck would barf on such a pointer as well). But you shouldn't be relying on the stack for large allocations anyway... -bob mckenzie, palmsource pdx. -----Original Message----- From: Mauck, Robert [mailto:[EMAIL PROTECTED]] Sent: Thursday, January 30, 2003 8:02 AM To: Palm Developer Forum Subject: Reliable invalid pointer check Hi, I am trying to come up with a reliable invalid pointer check. I am assuming that a valid pointer points to the beginning of a chunk (i.e. directly allocated with MemPtrNew or MemHandleLock). My first stab was to call MemPtrSize() on the pointer and compare the size to what I expect. This works okay, except on really whacky pointers the routine displays a Fatal error message and resets. I would like to intercept the reset and handle the error myself. I took a look at the OS4 source and there is a call PrvPtrCheck. That routine returns a MemChunkHeaderPtr. I do not want the header but that functionality without the error message is exactly what I am looking for. Is there a call I can make to disable the error messages so that this call will always return to me? Is there another technique I can use to verify that my pointer is valid? Thanks for any help, Rob Mauck -- For information on using the Palm Developer Forums, or to unsubscribe, please see http://www.palmos.com/dev/support/forums/ -- For information on using the Palm Developer Forums, or to unsubscribe, please see http://www.palmos.com/dev/support/forums/
