[Insight-developers] memcpy usage in itk and vtk

Bradley Lowekamp blowekamp at mail.nih.gov
Wed Apr 10 10:15:14 EDT 2013


Kent,

I am giving some comment to you patch now.

I agree with what you said.

If the thing you are copying is a template, typedef then std::copy should be used.

But there are many cases you change which use static_cast<char*>, in these cases you loose the type safety of std::copy, and I don't see the point of the change.

Brad

On Apr 10, 2013, at 10:09 AM, "Williams, Norman K" <norman-k-williams at uiowa.edu> wrote:

> The big issue I ran into with memcpy was where it happened in a case where
> it was copying an array of objects whose type was a template parameter,
> that could potentially be a C++ class type.
> 
> In that case it is potentially disastrous, and probably hard to debug.
> std::copy & std::fill have requirements with respect to the type of
> objects copied: they need to have an operator= (defined or default) or a
> constructor taking the fill type respectively.
> 
> In our templated code, throwing a compiler error by enforcing those
> constraints is a good thing; where memcpy could silently fail,
> std::copy/std::fill will complain.
> 
> --
> Kent Williams norman-k-williams at uiowa.edu
> 
> 
> 
> 
> 
> 
> On 4/10/13 9:04 AM, "Bradley Lowekamp" <blowekamp at mail.nih.gov> wrote:
> 
>> Bill,
>> 
>> I think that copy is required for generic programming like much of ITK.
>> 
>> But when you have a known type, I don't see any reason to look down on
>> memcpy.
>> 
>> Brad
>> 
>> On Apr 9, 2013, at 5:02 PM, Bill Lorensen <bill.lorensen at gmail.com> wrote:
>> 
>>> Kent says:
>>> "There are (before this patch) 88 calls to memcpy
>>> in the ITK source code."
>>> 
>>> In VTK, there are 2076 uses of memcpy in 452 classes.. Perhaps the
>>> older sibling can learn from the younger.
>>> 
>>> There are 34 uses of std::copy in vtk.
>>> 
>>> Bill
>>> 
>>> --
>>> Unpaid intern in BillsBasement at noware dot com
>>> _______________________________________________
>>> 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.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-developers
>> 
>> _______________________________________________
>> 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.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-developers
> 
> 
> 
> ________________________________
> 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