ムーブセマンティクスとは何か?
ムーブセマンティクスは、値がデータを複製する代わりに所有権を移すことで、ヒープ上のbufferなどの基盤となるリソースを別の値へ引き渡せるようにします。元のオブジェクトは安全に破棄できるよう、有効だが空の状態に残されます。これにより、大きなオブジェクトの高価なコピーを、ポインタレベルの安価な移動へと変えます。
なぜ重要か
コピーではなくムーブすることで、不要なアロケーションやディープコピーを避けられ、containerや大きなオブジェクトにとって大きなパフォーマンス上の利点になります。また、所有権の移動を型システムの中で明確に表現できます。
関連ガイド
What Is Ownership in Memory Management?Ownership is a model where each resource has a single owning variable responsible for freeing it, making clea…
What Is RAII?RAII ties a resource lifetime to an object lifetime, acquiring it on construction and releasing it automatica…
What Is Reference Counting?Reference counting tracks how many references point to an object and frees it automatically when that count d…