[Insight-developers] SmartPointer null check

Miklos Espak espakm at gmail.com
Wed Oct 19 17:49:46 EDT 2011


Hi Matt,

I do not think that the GUI user would create it, I only said that eventual
null pointer errors could be caught and would not cause a crash, what would
result more stable programs. Obviously, null pointer dereferencing is an
error that should be fixed, but in case of a GUI program it is nicer to see
an error dialog than to see the program being crashed. Also, if the bug is
not in our code fixing it can be hard, let it be either a closed or an open
source library.

I doubt that the check would cause much computational burden. In ITK the
most CPU intensive part of the execution are the iterations inside the
filters, the mathematical computations and the memory
allocations/deallocations. Iterators are accessed directly, they do not even
provide a ::Pointer typedef member. Moreover, if the speed is crucial and
there is a lot of dereferencing, you can still use normal (not smart)
pointers.

However, it would be nice to measure it on a big application with some
profiler tool, how many percentage of the execution would it take. Or to
locate code lines where a dereferencing happens inside of a loop.

I know that catching NPE-s is a bad practice, but even if they are not
caught, it is better to have a stack trace in the output then segmentation
fault.

Best,
Miklos


On Wed, Oct 19, 2011 at 8:06 PM, Matt McCormick
<matt.mccormick at kitware.com>wrote:

> Hi Miklos,
>
> In my humble opinion, it would be too much of a computational burden,
> and it usually indicates a logic bug in the code, not something a GUI
> user would create.
>
> Thanks,
> Matt
>
> On Wed, Oct 19, 2011 at 1:57 PM, Miklos Espak <espakm at gmail.com> wrote:
> > Hi,
> > would it be possible to make a NULL check in
> itk::SmartPointer::operator->
> > and operator* ?
> > I thought an std::runtime_error (or derivant) could be thrown if
> m_Pointer
> > is 0. In this way the application would not crash on null pointer
> > dereference but it could be caught from a GUI eventually. That could
> spare a
> > lot of null checks in the code.
> > Sorry, if this is a recurring topic of discussion or it is already
> > implemented in ITK 4.0. I use 3.20.0 as part of MITK.
> > Best regards,
> > Miklos Espak
> >
> > _______________________________________________
> > Powered by www.kitware.com
> >
> > Visit other Kitware open-source projects at
> > http://www.kitware.com/opensource/opensource.html
> >
> > Kitware offers ITK Training Courses, for more information visit:
> > http://kitware.com/products/protraining.html
> >
> > Please keep messages on-topic and check the ITK FAQ at:
> > http://www.itk.org/Wiki/ITK_FAQ
> >
> > Follow this link to subscribe/unsubscribe:
> > http://www.itk.org/mailman/listinfo/insight-developers
> >
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/mailman/private/insight-developers/attachments/20111019/33176adb/attachment.htm>


More information about the Insight-developers mailing list