memory readability
Anyone know of a way to tell if memory on the other end of a pointer is readable or writeable before you read or write to/from it? I can tell afterwords when I get a memory error, but by then the program has crashed.
-R
August 12, 2000 11:55 AM
For Windows you can use IsBadReadPtr and IsBadWritePtr.
You can also use exception handling. Wrap your code in a try block, do your stuff, and if the pointer is bad catch the exception. Whether or not this works in C++ using try/catch depends on your compiler and it''s settings. It does work in Windows using structured exception handling try/except/finally.
IsBadRead/WritePtr are simple to use but have limitations. They only check the pointer at that one time. If you''re using threads another thread can come along and change the memory the pointer points at and you''ll crash anyway. If you need your code to be bulletproof then use exception handling.
You can also use exception handling. Wrap your code in a try block, do your stuff, and if the pointer is bad catch the exception. Whether or not this works in C++ using try/catch depends on your compiler and it''s settings. It does work in Windows using structured exception handling try/except/finally.
IsBadRead/WritePtr are simple to use but have limitations. They only check the pointer at that one time. If you''re using threads another thread can come along and change the memory the pointer points at and you''ll crash anyway. If you need your code to be bulletproof then use exception handling.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement