[Insight-developers] SmartPointer null check

Williams, Norman K norman-k-williams at uiowa.edu
Thu Oct 20 10:46:18 EDT 2011


An end user should never see a program exception based on a NULL smart
pointer.  It is a software defect if they do.

The person writing the program, and anyone testing the program SHOULD see
early, often, loud failures if there is any attempt to dereference a NULL
smart pointer.  I don¹t see a big advantage to setting up a soft landing
for this.  And the checking would add overhead on an operation that
happens a lot, even in inner loops*

And what I've discovered during my adventures with gdb, if a program
detects a problem and throws an exception it can actually make it MORE
difficult to debug. If you dereference a NULL pointer the program stops at
the point of execution where the problem occurs. If an exception is thrown
it unwinds the stack and you can have a difficult time finding the context
of the error.

*if you know you're going to write a time-consuming inner loop, it would
probably be a performance win to acquire the regular pointer from the
Smart Pointer for the duration of the loop.  It might only save a couple
of instructions per iteration, but the cost of doing so is minimal.



________________________________
Notice: This UI Health Care e-mail (including attachments) is covered by the Electronic Communications Privacy Act, 18 U.S.C. 2510-2521, is confidential and may be legally privileged.  If you are not the intended recipient, you are hereby notified that any retention, dissemination, distribution, or copying of this communication is strictly prohibited.  Please reply to the sender that you have received the message in error, then delete it.  Thank you.
________________________________


More information about the Insight-developers mailing list