While true, I’d rather things be correct and then pointed out “this needs to be faster” than the reverse after a debugging session.
Note there are multiple pitfalls with memcpy
:
- it calculates in
bytes
, not objects (overflow on the manual multiplication is…a thing) - only works on POD types with trivial constructors (other types do not “exist” without their constructor being called; custom copy ctors may also block the destination from being valid objects)
- does not verify that the source and destination types are compatible
- alignment fun is probably lurking around here