私は趣味のC++プログラマーであり、現在(Ogre3Dを使用して)ゲームに取り組んでいます。メインクラスのメモリ割り当てについて質問があります。
私はメモリ割り当て、スタックに自動的に割り当て、ヒープに動的に割り当てること、およびそれらの違い(パフォーマンス、制限されたスタックサイズ)について多くのことを読みました。それでも、メインクラス(Application)と他のいくつかの「factory」クラス(Applicationクラスの単一インスタンスによって作成された)に何を使用すればよいかわかりません。これらはすべて、実行全体を通して単一のインスタンスが存在します。
以下は、レイアウトの簡略化されたスニペットです。
int main()
{
// like this (automatic)
Application app;
app.create(); // initializing
app.run(); // runs the game-loop
// or like this (dynamic)
Application* app;
app = new Application();
app->create();
app->run();
return(0); // only reached after exiting game
}
class Application
{
public:
Application(); // ctor
~Application(); // dtor
// like this, using 'new' in ctor and 'delete' in dtor (dynamic)
SceneManager* sceneManager_; // a factory for handling scene objects
DebugManager* debugManager_; // a factory for handling debugging objects
// or like this (automatic)
SceneManager sceneManager_;
DebugManager debugManager_;
};
スタックまたはヒープ(アプリケーションクラスとファクトリクラスの両方)にメモリを割り当てる方がよいですか?そして、どのような議論によって?
前もって感謝します!