[Insight-users] itk::SmartPointer in Container as Classelement

Bradley Lowekamp blowekamp at mail.nih.gov
Thu Mar 14 10:02:05 EDT 2013


Willi,

For classes which are container and hold objects using the SmartPointer direction is likely best. This is safest and will automatically maintain a reference count on the object you are containing. Now if you are putting them in an STL like container you may want to choose a list over a vector to minimize the copying of them, but that is a small detail that will really depend on how you are using the structure.

What do yo mean it's a "bad idea to copy [SmartPointers]"?

Inside tight loops ( things done on a per-pixel basis ), or places where the class already has a SmartPointer reference to the object, they don't need to be used.

Brad

On Mar 11, 2013, at 12:07 PM, Willi Huber <surfersparadise85-itk at yahoo.com> wrote:

> Hello all,
> 
> I am trying to write a Class that manages my data.
> The problem currently is that I am not aware how to use the itk::SmartPointer.
> 
> I have read its usually a bad idea to copy them. Another idea was to save the itk::SmartPointer* as suggested here: http://www.itk.org/pipermail/insight-users/2004-November/011095.html.
> The problem here is: Whenever the scope of the smartpointer creation is left the itk::SmartPointer* points to a the undefined RIP. And whenever I read any ITK manual it is strictly forbidden to use new.
> 
> So if anyone has just some time it would be nice to come up with a solution for my problem. Am I the first having these problems or am I just not smart enough?
> 
> Cheers,
> Willi
> _____________________________________
> 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://www.kitware.com/products/protraining.php
> 
> 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-users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20130314/d0dbcf93/attachment.htm>


More information about the Insight-users mailing list