I'm reading the book "Game Engine Architecture" where the author suggests declaring singletons as global variables, and later initialize each of them inside main() in the correct order.
Example from the book:
RenderManager gRenderManager;
PhysicsManager gPhysicsManager;
AnimationManager gAnimationManager;
TextureManager gTextureManager;
VideoManager gVideoManager;
MemoryManager gMemoryManager;
FileSystemManager gFileSystemManager;
// ...
int main( int argc, const char * argv ) {
// Start up engine systems in the correct order.
gMemoryManager.startUp();
gFileSystemManager.startUp();
gVideoManager.startUp();
gTextureManager.startUp();
gRenderManager.startUp();
gAnimationManager.startUp();
gPhysicsManager.startUp();
// ...
// Run the game.
gSimulationManager.run();
// Shut everything down, in reverse order.
// ...
gPhysicsManager.shutDown();
gAnimationManager.shutDown();
gRenderManager.shutDown();
gFileSystemManager.shutDown();
gMemoryManager.shutDown();
return 0;
}
Isn't it risky to create all these singletons on the stack? I mean, depending on the situation won't I get a stack overflow or something like that?
I apologize if it's a silly question, I'm just a little confused about the topic of where and when to allocate memory.