
Move Semantics In Unreal Engine
The Copy Problem In traditional C++ 98 programming you had two ways in which objects were created: From scratch and from copying. Foo(); // Default Ctor Foo(int x); // Parameterized Ctor Foo(const Foo& rhs); // Copy Ctor Foo& operator=(const Foo& rhs); // Copy Assignment Copying is usually more processor intensive to overcome this in C++ 11 move semantics were invented. Foo(Foo&& rhs); // Move Ctor void operator=(Foo&& rhs); // Move Assignment Moving objects is more memory efficient than copying (not every time). When to Implement Special Functions Deciding for which types to implement custom move constructors basically boils down to following the Rule of Three/Five/Zero, Just ask yourself one question: Does your type deal with ownership? Or, alternatively: Does your type allocate and/or manage (dynamic) resources? For Plain old datatypes For POD types or POD type members, moving is the same as copying. Imagine the difference between adding instances of either of the following two type
Continue reading on Dev.to
Opens in a new tab



