Click here to Skip to main content
15,917,538 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Multiple Instance of an application.... Pin
Leedoriden27-Nov-02 20:56
Leedoriden27-Nov-02 20:56 
GeneralRe: Multiple Instance of an application.... Pin
Neha27-Nov-02 21:07
Neha27-Nov-02 21:07 
GeneralRe: Multiple Instance of an application.... Pin
Rohit  Sinha28-Nov-02 10:07
Rohit  Sinha28-Nov-02 10:07 
GeneralRe: Multiple Instance of an application.... Pin
Alvaro Mendez29-Nov-02 9:50
Alvaro Mendez29-Nov-02 9:50 
QuestionHow to Merge two floating dialogbar into one floating tabbed dialogbar? Pin
Yu_Matrix27-Nov-02 20:26
Yu_Matrix27-Nov-02 20:26 
GeneralDownload manager like flashget, download accelator etc Pin
YogeshH27-Nov-02 20:14
YogeshH27-Nov-02 20:14 
GeneralPerformance cost of IsBadReadPtr and IsBadWritePtr... Pin
Matt Gullett27-Nov-02 19:56
Matt Gullett27-Nov-02 19:56 
GeneralRe: Performance cost of IsBadReadPtr and IsBadWritePtr... Pin
Patje27-Nov-02 21:05
Patje27-Nov-02 21:05 
I only use it in assert-statements, so that a bad-pointer is detected during development.
In a production version I only check for NULL-pointers.

I have the impression (but I'm not sure anymore), that the function is quite efficient as long as the pointer is valid. If the pointer is invalid, an internal exception is thrown, which is caught by the IsBadReadPtr function. In that case, there is a lot of overhead handling the exception, which makes it much slower.

You could always try to execute IsBadReadPtr in a loop and see its effect on a valid and on an invalid pointer.

But ... even if IsBadReadPtr returns success, it does not mean that the pointer is a valid pointer in your context. Suppose your pointer once pointed to e.g. a window structure, but that one has been freed, and its memory is now being reused by another data structure. Your window-pointer will then point to valid memory, but not to a window-structure anymore, which will crash your application later (in the best case), or corrupt other memory, files or your database (in the worst case). Therefore I wouldn't rely on IsBadReadPtr alone.

Another trick that can be used is to store a checksum in the first [four] bytes of a structure (or class). That way, you can always check the first bytes of your structure to see whether it is the kind of struct you would expect.
I do this sometimes (only in development versions, again for performance reasons).

<marquee>Enjoy life, this is not a rehearsal !!!
GeneralRe: Performance cost of IsBadReadPtr and IsBadWritePtr... Pin
Matt Gullett28-Nov-02 3:43
Matt Gullett28-Nov-02 3:43 
QuestionHow to deal with it ? thanks Pin
owen_200127-Nov-02 19:44
owen_200127-Nov-02 19:44 
QuestionWhat system dlls do I need to package? Pin
Jamie Hale27-Nov-02 19:32
Jamie Hale27-Nov-02 19:32 
AnswerRe: What system dlls do I need to package? Pin
Michael Dunn27-Nov-02 19:55
sitebuilderMichael Dunn27-Nov-02 19:55 
GeneralRe: What system dlls do I need to package? Pin
Jamie Hale27-Nov-02 20:11
Jamie Hale27-Nov-02 20:11 
GeneralNeed Code for these Pin
amandeeps27-Nov-02 18:50
amandeeps27-Nov-02 18:50 
GeneralRe: Need Code for these Pin
Michael Dunn27-Nov-02 19:29
sitebuilderMichael Dunn27-Nov-02 19:29 
GeneralDialog Windows Hidden Problem :: MFC Pin
valikac27-Nov-02 18:12
valikac27-Nov-02 18:12 
GeneralRe: Dialog Windows Hidden Problem :: MFC Pin
Peak27-Nov-02 20:31
Peak27-Nov-02 20:31 
GeneralRe: Dialog Windows Hidden Problem :: MFC Pin
valikac28-Nov-02 5:40
valikac28-Nov-02 5:40 
General"DestroyWindow" ---- Error!!!! Pin
liuty200627-Nov-02 17:21
liuty200627-Nov-02 17:21 
GeneralRe: "DestroyWindow" ---- Error!!!! Pin
Peak27-Nov-02 20:28
Peak27-Nov-02 20:28 
GeneralLoadLibrary and STDAPI Pin
devvvy27-Nov-02 16:55
devvvy27-Nov-02 16:55 
GeneralDocument Class and Dialog Windows :: MFC Pin
valikac27-Nov-02 16:02
valikac27-Nov-02 16:02 
GeneralRe: Document Class and Dialog Windows :: MFC Pin
Jonathan Craig27-Nov-02 16:32
Jonathan Craig27-Nov-02 16:32 
GeneralRe: Document Class and Dialog Windows :: MFC Pin
valikac27-Nov-02 16:36
valikac27-Nov-02 16:36 
QuestionHow can i start or stop Services Program which on the remote PC Pin
KeithPRC27-Nov-02 15:30
KeithPRC27-Nov-02 15:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.