Perhaps it is a question that would fit better on a site like stackoverflow but let’s give it a shot…
Posting it in this section because it’s a general C++ question and it doesn’t relate directly to UE4 or gameplay programming. Please move it to a more appropriate location if necessary.
Simply, the question is: is it legal to copy a C++ object using memmove/memcpy?
I am aware that it is generally a bad idea that might lead to a number of problems. Here’s what I am doing though:
- all objects are constructed using placement-new in a memory that was previously malloc’ed
- after moving an object from location A to location B the destructor on A is never called and the memory is just free’d
- all the shady operations are well-encapsulated so there should be no external pointers
So, the main question here is: does the Standard guarantee that after memcpy’ing an object from location A to location B the new object at the location B is still a valid object?
Thanks in advance!