我有一個結構/類是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