object-lifetime

Why would the behavior of std::memcpy be undefined for objects that are not TriviallyCopyable?

…衆ロ難τιáo~ 提交于 2019-11-26 12:22:41
From http://en.cppreference.com/w/cpp/string/byte/memcpy : If the objects are not TriviallyCopyable (e.g. scalars, arrays, C-compatible structs), the behavior is undefined. At my work, we have used std::memcpy for a long time to bitwise swap objects that are not TriviallyCopyable using: void swapMemory(Entity* ePtr1, Entity* ePtr2) { static const int size = sizeof(Entity); char swapBuffer[size]; memcpy(swapBuffer, ePtr1, size); memcpy(ePtr1, ePtr2, size); memcpy(ePtr2, swapBuffer, size); } and never had any issues. I understand that it is trivial to abuse std::memcpy with non-TriviallyCopyable

Object destruction in C++

爷,独闯天下 提交于 2019-11-26 10:16:53
When exactly are objects destroyed in C++, and what does that mean? Do I have to destroy them manually, since there is no Garbage Collector? How do exceptions come into play? (Note: This is meant to be an entry to Stack Overflow's C++ FAQ . If you want to critique the idea of providing an FAQ in this form, then the posting on meta that started all this would be the place to do that. Answers to that question are monitored in the C++ chatroom , where the FAQ idea started out in the first place, so your answer is very likely to get read by those who came up with the idea.) fredoverflow In the

When to use PerThreadLifetimeManager?

你说的曾经没有我的故事 提交于 2019-11-26 05:38:20
问题 I am following the example linked to below for setting up unity to work with my service layer. My project is setup very similar to the one in this article and I understand everything except why exactly is PerThreadLifetimeManager used when registering the service dependency. Keep in mind I am also using a generic repository and unitofwork that is being used in my service layer as well. Most unity examples use the default(transient) lifetime manager, and since my setup is similar to the one

Object destruction in C++

為{幸葍}努か 提交于 2019-11-26 01:57:48
问题 When exactly are objects destroyed in C++, and what does that mean? Do I have to destroy them manually, since there is no Garbage Collector? How do exceptions come into play? (Note: This is meant to be an entry to Stack Overflow\'s C++ FAQ. If you want to critique the idea of providing an FAQ in this form, then the posting on meta that started all this would be the place to do that. Answers to that question are monitored in the C++ chatroom, where the FAQ idea started out in the first place,