0

Hypotheticaly, if you have a large object that is needed almost everwhere within a program and this object is used for accessing data. Is it better to pass the object by referance into each function that needs it, or to make the object static?

For some context, I am most of the way through developing a game and have began to question some of my earlier engine decisions with regard to an object I called 'CentralAssetManager'.
It has only one instance and is used to load and enumerate all art assets used by the game so that each game object needs only an integer 'address' in order to referance an asset.

3
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by deceptikon
0

Hypotheticaly, if you have a large object that is needed almost everwhere within a program and this object is used for accessing data. Is it better to pass the object by referance into each function that needs it, or to make the object static?

Hypothetically, I'd question whether that large object is really needed everywhere or if it's just a lazy design. There's probably a better way to organize the program where that object's scope is limited or need for the object removed entirely.

On the other hand, global variables are one of those things that are easily abused, and that's why the advice is to avoid them. But when they really do provide the best option, they should be used carefully. Obfuscating things to avoid global variables isn't a better solution in my opinion.

Your CentralAssetManager might be best implemented as a singleton. It's still global, but much more controlled than just some random variable.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.