我有一个结构/类是partiall普通旧数据(POD)。memcpy结构的一部分
struct S {
// plain-old-data structs with only arrays and members of basic types (no pointers);
Pod1 pod1;
Pod2 pod2;
Pod3 pod3;
Pod4 pod4;
vector<int> more;
};
我复制S类的对象很多。 我想复制它与memcpy,但S ::更多阻止它。 我想避免调用4个memcpy,并使用它来获得额外的性能。 我应该这样做吗?
memcpy(s1, s2, sizeof(Pod1) + sizeof(Pod2) + sizeof(Pod3) + sizeof(Pod4);
我无法将它们打包在单独的结构中,因为它会摧毁所有使用pod1 - pod4的代码。
什么是最佳解决方案?
+1:聪明,应该想到这一点。 – Erik 2011-03-14 22:12:19