I'm making a small game in C++, and I'd like to keep track of all my loaded assets (Models...) so I only load them once. The only way I can figure to do this is to have some kind of global variable for the asset registry. Is there a better way?
Asked
Active
Viewed 64 times
1 Answers
0
Generally in C++ when it comes to global variables, there is always a better way. You could try a singleton or static class to hold all of your assets and have static functions to load them.

Gambit
- 954
- 9
- 15
-
Where: is there an essential, conceptual difference between a global variable and a singleton? Both represent a form of "global state"; and in that sense, a singleton is just a glorified global variable anyway (and very often, singletons are used as excuse to use global state, because, you know, now that there is a pattern for it, it can't be wrong to use that). – GhostCat Feb 11 '17 at 19:33
-
Thats not necessarily true. Singletons can have state but its also guaranteed that members are initialized and that its impossible to access to singleton before its creation. http://stackoverflow.com/questions/1463707/c-singleton-vs-global-static-object – Gambit Feb 12 '17 at 01:34