Back to list
dev_to 2026年3月7日

Unreal Engineにおけるメモリの転送機能

Move Semantics In Unreal Engine

Translated: 2026/3/7 8:06:18

Japanese Translation

典型的なおーけいC++98 エンジニアリングでは、オブジェクトが作成されるとき、2つの方法があります: 道を構築し、複製する。Fo() // コンストラクタ Foo (int x) // パーサ供給コンストラクタ Fo (&rhs) const; // コピーのコンストラクタ 引数はコピー操作を行います:Foo(& rhs); // オブジェクトのオーバーライドアサインメント 轻量化のため、C++11ではメモリの転送機能が存在し始めています。Fo(Foo&& rhs) // ボタンボックスコンストラクタ void (Foo&& rhs) // ボタンロード オブジェクトへの参照は指すか、ガレージコレクタによって管理されます このように、すべてを無視するのも手です: UObjectsの引数が、スマート パンクスであり、必ず引数が指すため、メモリ転送機能を使用して指定されることはありません。ブループラインコードでは使用しないでください。 函数パラメータにレフト引数またはスマート パンクスがあるとき Functionsのオーバー ライド アサインメントは通常使用されません。 UStructsは少数派でさえ、その頻繁性で受益するためには通常最適化です。それは一般的なデータ構造のみに過ぎます。 収録は、機能を持ち、それを見直すことをお勧めします:あなたのトペが所有権をお持ちですか? または、または代替:これはあなたが代碼を購入するときにデリバリーする(あるいはマネージメント) Dynamic(動的)リソースを管理でしょうか?std Smartパーカーの例を示すべきです:TUniquePtr / TSharedPtr / TWeakPtr を利用します。”この機能は、以下の場所で使用できません:UStructsは、これらの構造体を使用している場合と一致せます。UObjectsがスマート パンクに参照されるためには、すべてのオブジェクトを管理するガレージ コレクタが実装されていることになります。 オブジェクトのライフタイム管理を明確化し、容易にするために、この機能は必ず使用されません。ブループラインコードです。“UStructsが独自の遷移ロジックを規定しているため、しばしばより少ないメリットに受益するためです。これらの構造体には、常に動的な記憶領域を使用するような一般的なデータ構造を持つ場合ほど、それらは稀にその効果があります。”

Original Content

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). 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 std::vector: // when added, the pointer to the dynamic memory allocation of numbers can be copied to the new instance in the vector // sizeof(Foo) = 24 with gcc on Win64 // no reallocation necessary = possible performance gain struct Foo { // dynamic vector with 1000 entries std::vector numbers; } // When added, a full copy must be performed // sizeof(Bar) = 4000 with gcc on Win64 // All 1000 bytes need to be copied struct Bar { int numbers[1000]; } Unreal engine is a bit different when it comes to naming convention and even has some extra functionality Smart pointers are encouraged to be used with not blueprint exposed code whenever it adds clarity and simplifies object lifetime management. The Unreal equivalents to std smart pointers are: TUniquePtr TSharedPtr TWeakPtr It’s worth noting that all of this is not usable in the following contexts: UObjects cannot be moved or referenced by smart pointers as they are always referenced by pointer and managed by the garbage collector. Functions with r-value-reference or smart pointer parameters are not Blueprint exposable. UStructs may define custom move functionality, but rarely benefit from it, because they usually are plain data structs.