KDevVarLengthArray: memmove / memcopy?

Syron mr.syron at googlemail.com
Fri Jun 24 10:09:19 UTC 2011


> So my question: Would memmove/memcopy (which one should be used?) be more
> efficient?
>
I see the danger that plain memcpy calls do not call the elements' 
constructor or copy operator. I don't know how often or in what way 
KDevVarLengthArray is used, but I see several ways to work around that 
issue:

1) Make KDevVarLengthArray (VLA for short) use memcpy and subclass it 
for non-POD types. That would require some virtual methods (including a 
virtual destructor) and maybe that wouldn't scale for small arrays.
2) Same as above, but make the constructors of VLA private and create a 
factory method that returns a shared_ptr, and leave the destructor 
non-virtual. As far as I know (I think Scott Meyers said this), the 
shared_ptr implementation is able to call the destructor of the derived 
class though the pointer points to the base. That would be one virtual 
method less.
3) This is the best I think: Keep VLA but extend it by a template 
parameter that holds a copy function. Though this would mean to 
implement many copy/assignment operators.

Only my 2 cents,
-- Syron




More information about the KDevelop-devel mailing list