What are the disadvantages and overheads of a single-ton class?

Asked 2 years ago, Updated 2 years ago, 33 views

Hello, I am a beginner developer who is developing games with C++ and DirectX.

My question is that not only games but also various design patterns are applied when developing software Among them, Singleton has the advantage of easily accessing any source file instead of global variables I don't think there's much disadvantage as I use it comfortably.

The disadvantage that I know is that you have to use it when there is only one instance. The part that I apply to the actual game is SceneManager or BulletManager (which is used in many other places) and I usually use it as an object called 'Manager'? There seems to be no problem as long as it is used as one instance.

In any source file, GetInstance is defined as a macro without an exit and is easily accessed I think that the overhead that occurs at this time is more common sense than it exists as a class member variable. However, if the overhead is insignificant, I will continue to use it, but since the life of the game is FPS, I don't think even this can be ignored.

Anyway, what are the disadvantages of using a single tone pattern? Also, do you have enough overhead to care about? Is single tone used a lot in game development and software development?

singleton c++ overhead

2022-09-22 22:02

2 Answers

If you're worried about the overhead of calling a member function, You have to worry about the function itself.
I think it's right to say that it's not Mimi's level, but there isn't.

If it's a disadvantage, it's not a program problem I think it would be faster to find the disadvantages of the design pattern.
For example, the order of extinction between single-toned objects cannot be determined.
(Actually, it's not that there's no way...))
It's hard to test the units


2022-09-22 22:02

Just to answer the last sentence, single tone is nothing special. It's the most basic pattern in object-oriented programming. Single tone is also the most commonly used pattern in API.


2022-09-22 22:02

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.