[Insight-developers] Returning a smart pointer or a pointer?
Tom Vercauteren
tom.vercauteren at m4x.org
Mon May 19 13:22:14 EDT 2008
Hi all,
> The change will affect users that create a subclass and override the method.
This was indeed the backwards compatibility issue I was thinking of. I
just cannot really figure why someone would do something like that...
But as Bill said, this is unpredictable.
>> a) When the object to be returned is a member variable of the
>> class, then a raw pointer is returned, and preferably a
>> "const" raw pointer.
>>
>>
>> b) When the object to be returned is a newly created object,
>> then a SmartPointer is the preferred method, since it will
>> force users of this class to receive the value in a SmartPointer
>> and will prevent the returned object from "death in transit".
Ok thanks for the clarification.
> How much of a performance hit are you seeing?
>
> Maybe we will have to define a new method? Are their other classes
> that have the same p[problem?
I don' remember the exact performance hit. I was at least a few
percents since it was appearing on the profiler output. I haven't seen
any other problematic methods but haven't looked for it. I just check
the one that was appearing on the profiler output.
> What this function returns is a handle on an image. I fail to see the case
> where you'd be dereferencing this smart pointer often enough to affect
> program performance. If you are, you probably need to be using
> itk::ImageRegionIterator, or hoist calls to access methods via smart
> pointers outside of inner loops.
I understand that, but I am not responsible for the code calling this
method. It was somewhere in the demons registration hierarchy.
Tom
More information about the Insight-developers
mailing list