Original Post
Hi all - Recently there has been a lot of discussion about Singletons on the boards, and I've noticed a lot of people are staunchly against them. I think I understand a lot of the arguments, and I'm starting to agree that in general, Singletons are a Bad Idea(TM). However, I'm still not fully convinced that they're _always_ bad, which means I might still be missing something. The two conditions for Singletons being appropriate are - 1) Only one instance is allowed, having multiple instances would be incorrect 2) Global access is required Much of the conversation has been about various major engine components not being appropriate as Singletons. (Logging keeps being brought up as a possible exception) I've been working on a memory manager, and I'm starting to feel like it should definitely be a Singleton, since I'd like to route all allocations through it. Specifically, I feel like the final game system should have a Singleton Primary Memory manager, which would keep track of the heap. The primary logic I'm seeing is that if the whole system is supposed to run out of a single memory pool (like on a console), then it would almost certainly want global access (so everything can use dynamic allocation) and you definitely would want only one (there's only one hardware resource). I know that you could simply "choose" to only instantiate one PrimaryMemory manager, but it feels like it would be wise to have the code enforce it. Is there a problem with this logic? Is there a more appropriate way to handle this than as a Singleton? Anyhow, it is certainly possible that I'm missing some aspect of the discussion against Singletons, and if that is the case, I'd like to clear it up. Thanks for any help!